Hi,
in the most Playbooks about EC2 provisioning there exists a task which executes the pause module to wait for the instance to be available. Now that the EC2 module supports idempotency it is possible to run a playbook multiple times to add new features to an already provisioned instance. The problem now is that the pause module runs every time and waits for e.g. 2 minutes. I know that I can use ^C-c to continue the task. But I think the best solution would be to execute the wait task only after the instance was provisioned. Is there any possibility to achieve such a behavior?
Cheers,
Christian
I think the wait property on the EC2 module is exactly what I want.
Thanks
Hi Christian,
You are correct that there is a wait parameter to the ec2 module but
unfortunately it will probably not get you what you want since an ec2
instance in the "running" state does not necessary mean you can ssh to
it.
What we should probably add to this module is a wait for the system
status check to be 'ok' which is what I do typically when using boto
in python code.
To solve your immediate problem I wouldn't use a prompt; instead you
can wait for ssh to become available using the the wait_for module.
Example:
# register the var "ec2" when you launch it using the ec2 module
- 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 }}
state=started
port=22
delay=60
timeout=320
with_items: ec2.instances
As for idempotent behavior with the ec2 module you can use the id
parameter, see http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Run_Instance_Idempotency.html
-John
Thanks, works like a charm.
You should split your provisioning and configuration playbooks up, so that the provisioning playbook includes the configuration one.
Hi Michael,
now I have additionally split up the playbooks. But now if I try to execute only the configuration playbook, Ansible quits with the message: “no hosts matched”. In the provision playbook the hosts are added to the mongodb host group. But it seems that these group gets not persisted. Or do I miss something?
Thanks,
Christian
That’s probably because no hosts are in the group when you run the config playbook.
You would need to apply those roles to a group that includes hosts.