【问题标题】:Ansible: with_items over hosts in current playbook roleAnsible:with_items 在当前剧本角色中的主机上
【发布时间】:2019-02-26 06:00:30
【问题描述】:

我正在构建一个角色,我可能希望将其作为多个剧本的依赖项。我要支持:

clusterA.yml
- hosts:
  - clusterA
  roles:
  - clusterA

对比:

clusterB.yml
- hosts:
  - clusterB
  roles:
  - clusterB

在 clusterA 或 clusterB meta/main.yml 中,我可能有:

dependencies:
  - { role: commondependency }

好的,在设置 commondependency 时,我想 ssh-keyscan 集群中的其他主机。集群可以是clusterA,也可以是clusterB,也可以是clusterY。我可以找到很多这样的例子:

- name: Key Scan Cluster
  shell: ( ssh-keyscan {{item}} && cat /opt/commondependency/.ssh/known_hosts | sort | uniq ) > /opt/commondependency/.ssh/known_hosts
  with_items: hosts['clusterA']

但我真正想要的是:

- name: Key Scan Cluster
  shell: ( ssh-keyscan {{item}} && cat /opt/commondependency/.ssh/known_hosts | sort | uniq ) > /opt/commondependency/.ssh/known_hosts
  with_items: the hosts I am running a playbook on right now

【问题讨论】:

    标签: ansible ansible-playbook


    【解决方案1】:

    开始吧,http://docs.ansible.com/playbooks_variables.html底部提到的方式:

    - name: Key Scan Cluster
      shell: ( ssh-keyscan {{item}} && cat /opt/commondependency /.ssh/known_hosts | sort | uniq ) > /opt/commondependency/.ssh/known_hosts
      with_items: "{{ansible_play_hosts}}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-04
      • 2015-11-13
      • 1970-01-01
      • 2021-03-27
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多