我想强制 Ansible 在 playbook 中收集有关主机的事实(以在角色中使用这些数据)而不管 --limit,但不知道如何。
我有这样的剧本:
- hosts: postgres_access
tasks:
- name: Gathering info
action: setup
- hosts: postgres
roles:
- postgres
在“postgres”角色中,我有一个迭代默认 IP 的模板:
{% for host in groups['postgres_access'] %}
host all all {{hostvars[host].ansible_default_ipv4.address}}/32 md5
{% endfor %}
这就像魔法一样有效,但前提是我在没有 --limit 的情况下运行我的剧本。如果我使用 --limit 它会中断,因为主机组中的某些主机没有收集到的事实。
ansible-playbook -i testing db.yml --limit postgres
失败:[pgtest] (item=pg_hba.conf) => {"failed": true, "item": "pg_hba.conf", "msg": "AnsibleUndefinedVariable: 'dict object' 没有属性 'ansible_default_ipv4 '"
我怎样才能让 --limit 只重新配置 postgres 主机,并从其他主机获取网络数据(而不进行所有其他配置?)。
最佳答案
请试试这个!
- hosts: postgres
pre_tasks:
- setup:
delegate_to: "{{item}}"
with_items: "{{groups['postgres_access']}}"
roles:
- postgres
关于postgresql - 强制 Ansible 从组中收集事实,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37143533/