2

I installed cloud-init in openstack's image(centos-7),so how can I create a user with random password after instance launched (public key will also inject in this user)?

I wold not prefer copy script in instance launching panel, thank you all...

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
mrco
  • 1,995
  • 1
  • 10
  • 7

1 Answers1

1

There are options to generate the password for the in-built users using cloud-init:

Option-1: Using OpenStack horizon

If the user is using horizon to launch the instance then for the post-configuration by providing the config as:

#cloud-config
chpasswd:
  list: |
    cloud-user:rhel
    root:rheladmin
  expire: False

Here the passwords are generated for cloud-user and root users of RHEL image. The same is used for any user of any image simply by replacing the user.

Option-2: Using OpenStack heat template

Using the openstack heat template by providing the user-data as below:

heat_template_version: 2015-04-30

description: Launch the RHEL VM with a new password for cloud-user and root user

resources:
  rhel_instance:
    type: OS::Nova::Server
    properties:
      name: 'demo_instance'
      image: '15548f32-fe27-449b-9c7d-9a113ad33778'
      flavor: 'm1.medium'
      availability_zone: zone1
      key_name: 'key1'
      networks:
      - network: '731ba722-68ba-4423-9e5a-a7677d5bdd2d'
      user_data_format: RAW
      user_data: |
        #cloud-config
        chpasswd:
          list: |
            cloud-user:rhel
            root:rheladmin
          expire: False

Here the passwords are generated for cloud-user and root users of RHEL image. The same is used for any user of any image.

You can replace the rhel and rheladmin with your desired passwords.