Ask Your Question

cloud-init, fetching userdata late

asked 2014-11-13 05:38:23 -0500

Ukesh gravatar image

I am creating a server using Heat Template having user-data. User-data will create a file (/tmp/info.txt) in the virtual machine.

And I am running a python script ( which is in 'bootcmd' module. In the script (, i am referring the file '/tmp/info.txt', but it is not created at that time of executing the python script.

'/tmp/info.txt' file is creating some time late, i.e. after executing the script (

If I place the in 'runcmd', then it is working fine, but it affects the some other processes (x, y). processes (x, y) need to run after script executed.

Need following details: 1. When will cloud-init will fetch the user-data and execute it ? 2. How to get user-data before executing bootcmd module itself ?

Following is the heat template, I have used

. . .
. . .
    type: OS::Nova::Server
      flavor: { get_param: flavor_name }
      image: { get_param: image_name }
      name: { get_param: vm_name }
        - port: { get_resource: vm_port }
            template: |
                #!/usr/bin/env bash
                #Path of file
                rm $pathofconf

                json=$(printf "{\"Hosts\":[\"%s\"],\"DomainName\":\"%s\"}" $ip0 $domain_name )
                #Writing to StartUp Config file
                cat <<EOF >$pathofconf

                $ip0: { get_attr: [vm_port, fixed_ips, 0, ip_address] }
                $domain_name: { get_param: domain_name }

    type: OS::Neutron::Port
      network_id: { get_param: network_id }
          - subnet_id: { get_param: subnet_id }
. . .
. . .


user: ec2-user
disable_root: 0
ssh_pwauth:   1

cc_ready_cmd: ['/bin/true']
locale_configfile: /etc/sysconfig/i18n
mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
ssh_deletekeys:   0
ssh_genkeytypes:  ~
ssh_svcname:      sshd
syslog_fix_perms: ~

 - bootcmd
 - resizefs
 - set_hostname
 - rsyslog
 - ssh

 - mounts
 - ssh-import-id
 - locale
 - set-passwords
 - timezone
 - puppet
 - disable-ec2-metadata

 - rightscale_userdata
 - runcmd
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - keys-to-console
 - phone-home
 - final-message

# vim:syntax=yaml

- python /etc/
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-11-13 13:11:29 -0500

larsks gravatar image
  1. When will cloud-init will fetch the user-data and execute it ?

These are two separate steps. cloud-init fetches the user-data before doing anything, because your user-data can contain configuration information that overrides the defaults in /etc/cloud/cloud.cfg. When various configuration steps are executed depends entirely on the cloud-init configuration. For each stage (cloud_init, cloud_config, cloud_final), configuration modules are executed in the order in which they are listed in the file.

  1. How to get user-data before executing bootcmd module itself ?

Why don't you just run /etc/ at the end of your user-data script?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2014-11-13 05:36:37 -0500

Seen: 2,188 times

Last updated: Nov 13 '14