ec2_lc - launch configuration user data - uploads to aws OK but disappears!!

Hi all

Got a weird issue where I’m trying upload a bash script as user-data - via the launch config module.

Any help regarding this is appreciated - even if it’s a method of debugging this - there are no errors which is why I’m confused.

I’m sucking in the user-data as a file which seems fine as ansible reports no errors.

However, the instance launched doesn’t show any user-data as registered and the launch config web console does not tell me anything about my file.

The output from ansible is below:

`

TASK: [lc | Launch Configs] ***************************************************
ok: [localhost] => (item={‘instance_type’: u’t2.small’, ‘lc_security_groups’: u’sg-b1423ad4’, ‘image_id’: u’ami-edfd6e9a’, ‘lc_name’: ‘OpenVPNAS’, ‘assign_public_ip’: True, ‘user_data’: u’#!/bin/bash\n\n# Setup the ansible repo\napt-get install software-properties-common\napt-add-repository ppa:ansible/ansible\n# Refresh apt\napt-get update\n# Install ansible\napt-get install ansible\n# Setup env vars\necho “localhost” > ~/ansible_hosts\nexport ANSIBLE_HOSTS=~/ansible_hosts\n# Setup ssh for git pull\nmkdir /root/.ssh\n\nSSH_PRIV=“-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAyb2wJh.SSH-KEY-REMOVED-BY-STPHEN…RuzLaDA==\n-----END RSA PRIVATE KEY-----”\nKNOWN_HOSTS='github.com,192.30.252.128 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='\n\necho $SSH_PRIV > /root/.ssh/id_rsa\nchmod 600 /root/.ssh/id_rsa\n\necho $KNOWN_HOSTS > /root/.ssh/known_hosts\nchmod 644 /root/.ssh/known_hosts\nchown -R root /root/.ssh\n\nansible-pull -C master -U git://github.com/trainsmart/ansible.git -d /root/ansible\nexit 0’})

`

When I ssh to the launched instance, there is nothing in cloud-init to tell me that any user data is present:

`
root@ip-172-16-0-125:/var/lib/cloud/instances/i-5b761dbd# cat user-data.txt
root@ip-172-16-0-125:/var/lib/cloud/instances/i-5b761dbd#

`

I’m wondering if I need to supply the file in some format other than “normal” but the ec2_lc module documentation isn’t very explicit about this. From what I read, you just need to supply the file as a “normal” text file, not a mime formatted blob.

ansible version: ansible 1.8.4
environment: OSX Yosemite

Any help regarding this is appreciated - even if it’s a method of debugging this - there are no errors which is why I’m confused.

I repeated my launch config with a bash script of:

#!/bin/bash echo"hello world"

The resulting output:

`

TASK: [lc | Launch Configs] ***************************************************
changed: [localhost] => (item={‘instance_type’: u’t2.small’, ‘lc_security_groups’: u’sg-b1423ad4’, ‘image_id’: u’ami-edfd6e9a’, ‘lc_name’: ‘OpenVPNAS’, ‘assign_public_ip’: True, ‘user_data’: u’#!/bin/bash\necho “Hello world”'})

`

Shows that the user data is being sucked in.

However, we STILL don’t get any user data read into the Launch Configuration.

I am going to raise this as a bug.

Ah, OK - ignore me.

I wrote a module to handle the launch config creation and my module wasn’t ingesting the user_data because it wasn’t set up to do so.

Once I added the user-data as a parameter, it worked OK - working code below.

`

  • name: Launch Configs
    ec2_lc:
    aws_access_key: “{{ aws_access_key }}”
    aws_secret_key: “{{ aws_secret_key }}”
    region: “{{ region }}”
    state: present
    name: “{{ item.lc_name }}”
    assign_public_ip: “{{ item.assign_public_ip }}”
    image_id: “{{ item.image_id }}”
    key_name: “{{ lc_pem_key }}”
    security_groups: [ “{{ item.lc_security_groups }}”]
    instance_type: “{{ item.instance_type }}”
    instance_profile_name: standard-instance
    user_data: “{{ item.user_data }}”
    with_items: lc_list
    `

Hi Stephen,

Can you please help me with the below script for the user data?

I just wanted user data to run “source /home/centos/startup.sh” when the server starts.

I had used this

user_data:
{
#!/bin/bash
source /home/centos/startup.sh
}

but it didn’t work.
Can you please help me with this?

Thanks,
Rohit

Hi,

The user_data must be the actual script you want to run, so it shouldn’t have any additional formatting and should start with #!/bin/bash.

Something like this should work:

user_data: |
#!/bin/bash
source /home/centos/startup.sh

kind regards
Pshem