# ec2\_lc - launch configuration user data - uploads to aws OK but disappears!!

**URL:** <https://forum.ansible.com/t/ec2-lc-launch-configuration-user-data-uploads-to-aws-ok-but-disappears/17748>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [March 16, 2015, 9:57am UTC](https://forum.ansible.com/t/ec2-lc-launch-configuration-user-data-uploads-to-aws-ok-but-disappears/17748 "2015-03-16T09:57:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Tan](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephen\_Tan](https://forum.ansible.com/u/Stephen_Tan)\
**Post date:** [March 16, 2015, 9:57am UTC](https://forum.ansible.com/t/ec2-lc-launch-configuration-user-data-uploads-to-aws-ok-but-disappears/17748/1 "2015-03-16T09:57:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stephen\_Tan](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephen\_Tan](https://forum.ansible.com/u/Stephen_Tan)\
**Post date:** [March 16, 2015, 12:53pm UTC](https://forum.ansible.com/t/ec2-lc-launch-configuration-user-data-uploads-to-aws-ok-but-disappears/17748/2 "2015-03-16T12:53:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stephen\_Tan](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephen\_Tan](https://forum.ansible.com/u/Stephen_Tan)\
**Post date:** [March 16, 2015, 2:26pm UTC](https://forum.ansible.com/t/ec2-lc-launch-configuration-user-data-uploads-to-aws-ok-but-disappears/17748/3 "2015-03-16T14:26:23Z")

</div>

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  
`

---

<div class="post-metadata">

**Author:** ![Rohit\_Maheshwari](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@Rohit\_Maheshwari](https://forum.ansible.com/u/Rohit_Maheshwari)\
**Post date:** [August 16, 2017, 12:08pm UTC](https://forum.ansible.com/t/ec2-lc-launch-configuration-user-data-uploads-to-aws-ok-but-disappears/17748/4 "2017-08-16T12:08:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [August 16, 2017, 9:44pm UTC](https://forum.ansible.com/t/ec2-lc-launch-configuration-user-data-uploads-to-aws-ok-but-disappears/17748/5 "2017-08-16T21:44:16Z")

</div>

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
