Hi all,
Following the example in http://www.ansibleworks.com/docs/modules.html#ec2 I have the bellow playbook :
ec2-example.yml :
“”"
Launch instances, runs some tasks - name: Define mysql launch hosts: localhost gather_facts: False vars: keypair: my_keypair instance_type: m1.small security_group: my_securitygroup image: my_ami_id region: us-east-1 tasks: - name: Launch instance local_action: ec2 keypair={{ keypair }} group={{ security_group }} instance_type={{ instance_type }} image={{ image }} count=5 wait=true region={{ region }} register: ec2 - name: Add new instance to host group local_action: add_host hostname={{ item.public_ip }} groupname=launched with_items: ec2.instances - name: Wait for SSH to come up local_action: wait_for host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started with_items: ec2.instances - name: Configure instance(s) hosts: launched sudo: True gather_facts: True roles: - mysql_role
“”"
As you can see this will launch 5 mysql servers ( count=5) , the configuration of all mysql servers is almost the same since they are part of the same mysql_role. the only small difference is that I have in my roles a variable that defines if the mysql server will be the master or slave. Is there a way to define that the first instance launched will be the master and the rest will br slaves ??? This is not only a mysql setup case but I have more cases where servers are been setup by the same role but differ because of a variable…
I know I could separate the above in two different tasks or playbooks and use the add_host hostname={{ item.public_ip }} groupname=mysql-master / groupname=mysql-slave but I’m wondering if I could do this in a single playbook.
Also is there a way I could add the servers from the add_host to a local file ?
Regards,
Nicolas.