2016-11-08 66 views
0

我有以下ansible playbook。Ansible使用另一種遊戲中的一個遊戲的ec2公共ip

--- 

- name: Ansible playbook to create a new aws dev instance 
    hosts: localhost 
    roles: 
    - aws 

- name: Set up the dev server 
    hosts: 
    roles: 
    - services 

aws角色,我創建一個EC2實例,並註冊爲ec2_instance。我將如何在第二次播放的主機中使用新創建的實例的公共IP。

我應該使用類似hosts: ec2_instance.public_ip的東西嗎?

+0

你應該使用'add_host',參見[實例](文檔中的http://docs.ansible.com/ansible/ec2_module.html)。 –

回答

1

您可以考慮使用add_host。把這個在您的第一齣戲(獲得新的虛擬機的IP化後):

- name: Adding a new host in inventory file. 
    add_host: name=someName ansible_ssh_host="{{your_ip}}" ansible_ssh_pass=*** groups=new_group 

,然後在第二個上場的使用這個組:

- name: Set up the dev server 
    hosts: new_group