在同一剧本中有两个不同主持人的两个戏剧与依赖

时间:2017-04-06 11:42:14

标签: ansible devops ansible-2.x

Senario:

1. I need to run two plays in a single playbook.
2. The second play should run after the first play.
3. The first play create few instance and update the inventory file by making new group.
4. Second play uses the updated group and install few packages.

问题:如果我分别在两个游戏中运行,那么它就会成功。 但是,我需要在相同的脚本中使用它们。

我认为问题是并行播放。

提前谢谢。

---
 - name: ec2
   hosts: localhost
   connection: local
   roles:
   - launchEc2
 - hosts: ansible
   gather_facts: Fasle
   become: yes   
   roles:
   - python

输出:

PLAY [ec2] *********************************************************************

TASK [setup] *******************************************************************
ok: [127.0.0.1]

TASK [launchEc2 : include_vars] ************************************************
ok: [127.0.0.1]

TASK [launchEc2 : Launch new ec2 instance] *************************************
changed: [127.0.0.1]

TASK [launchEc2 : Add ec2 ip to the hostgroup] *********************************
changed: [127.0.0.1] => (item={.....})

TASK [launchEc2 : wait for SSh to come up] *************************************
ok: [127.0.0.1] => (item={.....})

PLAY [ansible] *****************************************************************

TASK [python : install python] *************************************************
skipping: [34.203.228.19]

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=5    changed=2    unreachable=0    failed=0   
34.203.228.19              : ok=0    changed=0    unreachable=0    failed=0

1 个答案:

答案 0 :(得分:1)

Ansible在处理剧本之前加载库存。

在你的情况下,第二个游戏与第一个游戏中的修改之前的库存相同。

通常,在配置云主机时,您可能希望使用add_host将新主机动态添加到内存清单中,以便后续播放可以使用它们。

您还可以尝试在修改广告资源后调用meta: refresh_inventory,但我不确定它是否适用于更新静态广告资源。