Discussion:
[ansible-project] How to install the packages using EC2 user data at the launch time
Arbab Nazar
2015-07-27 07:26:01 UTC
Permalink
I want to install the nginx by passing it as the user data to the ec2
instance at the launch time. I am passing it like this

- name: WebServer | Create the WebServer Instance(s)
local_action:
module: ec2
region: "{{ vpc_region }}"
group: "{{ ec2_security_groups[1].sg_name }}"
keypair: "{{ key_name }}"
instance_type: "{{ web_instance_type }}"
*user_data: "sudo apt-get install nginx -y"*
image: "{{ imgae_id.ami }}"
vpc_subnet_id: "{{ public_subnet }}"
#private_ip: "{{ nat_private_ip }}"
assign_public_ip: True
wait: True
wait_timeout: 600

But the above method didn't work for me although it has created the EC2
instance successfully but didn't install the nginx.

Can you please point me in the right direction. Thanks
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4223055a-f9f7-4204-ad51-c6cae53cb9a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jon Hadfield
2015-07-27 17:57:43 UTC
Permalink
I had the same issue on Centos, i.e. I added a script and nothing happened.
Not tried on Debian based distros, but I found building a base AMI with
cloud-init installed and, in /etc/cloud/cloud.cfg set 'disable_root:
false', solved it for me. Then launch an instance of that base AMI, setting
the user-data.
In my case it wasn't an ansible issue, but a limitation of the AMI I chose.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ed829261-5858-4457-b6f3-01ce4d2566e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Timothy Gerla
2015-07-27 18:00:49 UTC
Permalink
It's been a long time since I've used cloud-init, but I believe that your
script needs to start with a bangline (#!/bin/sh) for cloud-init to
interpret it as an on-boot script.

Regardless, I think a better approach would be to use Ansible and the apt
module to ensure that the package is installed post-boot, not just running
a script on boot.

-Tim
Post by Jon Hadfield
I had the same issue on Centos, i.e. I added a script and nothing
happened. Not tried on Debian based distros, but I found building a base
AMI with cloud-init installed and, in /etc/cloud/cloud.cfg set
'disable_root: false', solved it for me. Then launch an instance of that
base AMI, setting the user-data.
In my case it wasn't an ansible issue, but a limitation of the AMI I chose.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/ed829261-5858-4457-b6f3-01ce4d2566e2%40googlegroups.com
<https://groups.google.com/d/msgid/ansible-project/ed829261-5858-4457-b6f3-01ce4d2566e2%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAH4wdVWJ4eOBvEjC%3DVMy-Z7WGpXFUZAz%2B%3Db-7yhpc%2BY%2BcjAY8g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...