ansible中变量的应用

ansible中变量的引用方式

通过文件管理变量,在剧本文件中加载

- name: 集群管理
  gather_facts: "{{ facts }}"
  gather_facts:  true
  hosts:  "{{ myhost }}"
  vars_files:
    - config /global_vars .yml
  roles:
    -  "{{ role }}"

运行剧本时增加 -e 参数进行指定

ansible-playbook -i hosts site.yml -e "myhost=cyberAcq role=test"

zookeeper myid 文件生成

{% for ip in groups['zookeeper'] %}
{% if ansible_facts[netcard]['ipv4']['address'] == ip %}
{{ loop.index }}
{% endif %}
{% endfor %}

posted @ 2022-04-07 11:48  不着陆的牛  阅读(30)  评论(0)    收藏  举报