postgresql - 强制 Ansible 从组中收集事实

标签 postgresql ansible ansible-facts

我想强制 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/

相关文章:

sql - SERIAL 外键可以设置为空吗?

sql - 如何查询结果中遗漏的数据

Ansible:如何使用 yaml 指定数组或列表元素事实?

python - 本地事实(facts.d)和安装模块

ansible - 如何在ansible中循环主机名或IP

Ansible主机文件如何在ansible_ssh_pass中提供#

postgresql - 如何获得搜索多个术语以使用索引的 hstore 查询?

postgresql - 在 ec2 实例上部署 Java EE webapp

ansible - 在主机上执行任务的正确方法

bash - Ansible 1.9.1 'become' 和 sudo 问题