Ansible 在具有依赖关系的同一剧本中使用两个不同主机进行两次播放

Ansible 在具有依赖关系的同一剧本中使用两个不同主机进行两次播放,ansible,devops,ansible-2.x,Ansible,Devops,Ansible 2.x,塞纳里奥: 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

塞纳里奥:

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

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

在您的情况下,第二个重头戏的库存与第一个重头戏修改前的库存相同

通常,在配置云主机时,您可能希望使用
add\u host
将新主机动态添加到内存资源清册中,以便后续播放时可以使用这些主机


您也可以尝试在清单修改后调用
meta:refresh\u inventory
,但我不确定它是否可以用于更新静态清单。

我认为问题在于您手动更新主机文件,而不是使用
add\u host
。我正在使用lineinfle更新主机。。。。有什么问题吗?我尝试了“添加主机”现在第二个播放可以执行了,但它显示跳过将播放手册片段和日志输出添加到原始问题。是否应
meta:refresh\u inventory
应在第二个播放之前添加?感谢@Konstantin Suvorov添加
add\u host
工作,但是,新ip未添加到资源清册文件。。。