ansible不同的部分,不同的主机相同的剧本

时间:2017-08-14 23:03:18

标签: ansible devops

我有一个用例,我需要做一个任务(重新发布ssl证书)。步骤如下:

  • 在CA服务器上打开端口
  • 在与CA联系的普通服务器上生成证书
  • CA服务器上的关闭端口

这意味着我有一个看起来像这样的剧本:

- name: open port
  hosts: caserver
  become: yes
  tasks:
    - name: open firewall
      iptables: chain=FWR protocol=tcp source={{ item }} destination_port=8888 jump=ACCEPT state=present
      with_inventory_hostnames: WHAT IS HERE???

- name: generate ssl certificate
  hosts: all:!caserver
  become: yes
  roles:
    - sslcert

- name: close port
  hosts: caserver
  become: yes
  tasks:
    - name: close firewall
      iptables: chain=FWR protocol=tcp source={{ item }} destination_port=8888 jump=ACCEPT state=absent
      with_inventory_hostnames: WHAT IS HERE???

然后我会从命令行调用它来使用限制来控制重新发布的机器。

ansible-playbook -i hosts -l myserver,caserver -c ssh --ask-vault-pass -K generate_certs.yml

问题是我没有在caserver上打开那个端口。

我一直在尝试一些magic variables,但没有运气。

我想我必须在hosts文件中创建一个组然后使用它。所以我创建一个小组,重新发布,然后从该小组中删除它们。

我不喜欢那种洗牌是否有更好的方式在ansible?

1 个答案:

答案 0 :(得分:0)

您应该使用delegation

https://spreadsheets.google.com/feeds/list/--KEY--/od6/public/values?alt=json-in-script