Existing deployment

If we already have instances running, the previous tasks are skipped and the single task in roles/ec2/existing_deployment.yml is run. This task simply takes one of the running hosts and adds it to the host group named ec2_instance:

- name: add one of our running instances to a host group for use in the next step  add_host:    name: "{{ groups['already_running'][0] }}"    ansible_ssh_host: "{{ groups['already_running'][0] }}"    groups: "ec2_instance"

This leaves us in the same position as we were in at the end of the new deployment tasks, with a host called ec2_instance with a single instance that is accessible over SSH.

Get Learn Ansible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.