
# cloud-init-0.7.9及以上版本配置
1. 添加如下键值对，前后各空出一行：
   ```
   no_ssh_fingerprints: true
   ```
   
2. 设置ssh_pwauth，该选项表示是否支持ssh密码登录。true为启用，false或0为禁用。
   ```
   ssh_pwauth: true
   ```
   
3. 修改disable_root为false。该参数表示是否禁用远程ssh root登录。
   ```
   disable_root: false
   ```
   
4. 添加preserve_hostname: false。
   ```
   preserve_hostname: false
   ```
   
5. 使用"#"注释掉以下语句（不存在忽略）：
   ```
   mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
   resize_rootfs_tmp: /dev
   ssh_deletekeys:   0
   ```
   
6. 修改ssh_genkeytypes为下面语句（不存在添加）：
   ```
   ssh_genkeytypes: ['rsa', 'dsa']
   ```
   
7. 修改syslog_fix_perms为下面语句（不存在添加）：
   ```
   syslog_fix_perms: root:root
   ```
   
8. 添加下面语句：
   ```
   network:
      config: disabled
   datasource_list: [ OpenStack ]
   datasource:
     OpenStack:
       metadata_urls: ['http://169.254.169.254']
       max_wait: 120
       timeout: 10
       retries: 5
   ```
   
9. （可选）在"/etc/cloud/cloud.cfg"中配置"apply_network_config: False"。 对于使用Cloud-Init 18.3及以上版本的用户，需执行本操作
   ![](https://support.huaweicloud.com/bpicg-bms/zh-cn_image_0000001212466429.png "点击放大")
   
10. 在cloud_final_modules段的"- final-message"后面添加一句：
    ```
    - power-state-change
    ```
    
11. 查看并修改system info中的信息：
    ```
    system_info:
       distro: rhel
       default_user:
         name: root   //登录操作系统使用的用户名
         lock_passwd: False   //True表示禁用密码登录方式，注意部分操作系统此处配置为1表示禁用
    ```
    其中，distro参数需要根据具体操作系统类型修改，比如distro: rhel、distro: ubuntu、distro: debian、distro: fedora等。
    
12. 除**cloud-init 23.x** 以外的版本，修改如下源码：
    源码路径：xxx/xxx/cloudinit/sources/DataSourceOpenStack.py
    - 新增"return True"行。
    
    - 删除"(DataSourceOpenStackLocal, (sources.DEP_FILESYSTEM,)),"行。
    
    
    ```
    def detect_openstack(accept_oracle=False):
         """Return True when a potential OpenStack platform is detected."""
         return True
         if not util.is_x86():
             return True  # Non-Intel cpus don't properly report dmi product names
         product_name = util.read_dmi_data('system-product-name')
    ......
     # Used to match classes to dependencies
     datasources = [
         (DataSourceOpenStack, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
     ]
    ```
    
13. 针对**cloud-init 23.x** 版本及以上版本，修改如下源码：
    - 源码路径：xxx/xxx/cloudinit/sources/DataSourceOpenStack.py，删除"(DataSourceOpenStackLocal, (sources.DEP_FILESYSTEM,))"行。
      ```
      # Used to match classes to dependencies
       datasources = [
           (DataSourceOpenStack, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
       ]
      ```
      
    
    - 源码路径：xxx/xxx/cloudinit/sources/__init__.py，修改"return_value = self._check_and_get_data()"为"return_value = self._get_data()"。
      ```
      def get_data(self) -> bool:
          """Datasources implement _get_data to setup metadata and userdata_raw.
          Minimally, the datasource should return a boolean True on success.
          """
          self._dirty_cache = True
          return_value = self._get_data()
          if not return_value:
              return return_value
          self.persist_instance_data()
          return return_value
      ```
      
     
 
