Ask Your Question
0

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 (generate.py) which is in 'bootcmd' module. In the script (generate.py), 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 (generate.py).

If I place the generate.py in 'runcmd', then it is working fine, but it affects the some other processes (x, y). processes (x, y) need to run after generate.py 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

. . .
. . .
resources:
  vm:
    type: OS::Nova::Server
    properties:
      flavor: { get_param: flavor_name }
      image: { get_param: image_name }
      name: { get_param: vm_name }
      networks:
        - port: { get_resource: vm_port }
      user_data: 
        str_replace:
            template: |
                #!/usr/bin/env bash
                #Path of file
                pathofconf=/tmp/info.txt
                rm $pathofconf

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

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

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

/etc/cloud/cloud.cfg

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: ~

cloud_init_modules:
 - bootcmd
 - resizefs
 - set_hostname
 - rsyslog
 - ssh

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

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

# vim:syntax=yaml

bootcmd:
- python /etc/generate.py
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

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/generate.py 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

Stats

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

Seen: 1,965 times

Last updated: Nov 13 '14