i had launched 2 instances using the following code
- name: Launch the new EC2 Instance
ec2:
key_name : "{{keypair}}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
wait: true
region: "{{ region }}"
count: "{{count}}"
volumes:
- device_name: /dev/sda1
volume_type: gp2
volume_size: 8
instance_tags:
Name : awslab
# assign_public_ip : yes
register: ec2
i want to save details in the form of
[webservers]
ipofinstance1
[monitoring-servers]
ipofinstance2
how to store the above format to hosts file
with same instance for both groups i have used the following code and it worked now i want to add different ip in different groups.
i tried this
- name: Add the newly created EC2 instance(s) to the host file
blockinfile:
path: hosts
create: yes
block: |
[webservers]
{{item.public_ip}}
[monitoring-servers]
{{item.public_ip}}
with_items: '{{ec2.instances}}'
become: yes
Any suggestions for making the output in the above specified format Thanks:)