hosts: launched

23 views
Skip to first unread message

William Donnelly

unread,
May 10, 2016, 3:12:14 PM5/10/16
to Ansible Project
Hello, 

Has anyone found the correct syntax for launching a temporary ec2 instance with Ansible, doing some config on it, then using the newly created ip address of the ec2 instance in the
the host inventory. 

This part is all good:

---
- name: Base-API-AMI | Create a Base-AMI for the API ECS Cluster
  hosts: localhost
  connection: local
  gather_facts: False
  tasks:

    - name: check that env was passed in extra-vars
      assert:
        that: 'env is defined'

    - include_vars: "{{ inventory_dir }}/vars/{{ env }}.yml"

    - name: create Temporary Instance based on CentOS 7
      ec2:
        key_name: "{{ key_name }}"
        instance_type: t2.micro
        image: ami-d2c924b2
        instance_tags:
          name: dockerhost
        wait: true
        region: us-west-2
        assign_public_ip: no
      register: ec2

    - debug: var=ec2

-------------- This part fails --------------------------------

 - name: Add new instance to host group
      add_host: hostname={{ item.public_ip }}
      with_items: ec2.instances


----------- this pattern also fails

    - name: change hosts inventory
      hosts: launched
      sudo: True
      gather_facts: True


Thanks,
Bill


NOTICE TO RECIPIENT(S) OF INFORMATION: This message may contain information that is proprietary or confidential to NeoCare Solutions or its subsidiaries, and is for your use only. This message may also contain Personally Identifiable Information or Protected Health Information, including various kinds of information about specific medical or mental health conditions, procedures, medications, etc. Disclosure of any such information to anyone other than the recipient of this message is restricted by Federal laws and regulations, State laws and regulations, or both. Unless it is otherwise permitted by such laws and regulations, any disclosure of this information requires the express written consent of the person to whom it pertains. If you have received this message in error, please notify the sender immediately by return e-mail and delete the message and any attachments. Thank you.
Reply all
Reply to author
Forward
0 new messages