I want to install 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 }}"
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
When a user data script is processed, it is copied to and run from /var/lib/cloud/instances/ instance-id / . The script is not deleted after it is run. Be sure to delete the user data scripts from /var/lib/cloud/instances/ instance-id / before you create an AMI from the instance.
You are missing the shebang, try the following:
- 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: |
#!/bin/sh
sudo apt-get install nginx -y
image: "{{ imgae_id.ami }}"
vpc_subnet_id: "{{ public_subnet }}"
assign_public_ip: True
wait: True
wait_timeout: 600
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With