首页 文章

Ansible在另一个游戏中使用ec2 public ip of one play

提问于
浏览
0

我有以下ansible剧本 .

---

- 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 这样的东西吗?

1 回答

  • 1

    您可以考虑使用add_host . 把它放在你的第一场比赛中(在获得新的vm之后):

    - 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
    

相关问题