【问题标题】:set ip node from inventory to default/main.yaml将 ip 节点从清单设置为 default/main.yaml
【发布时间】:2018-11-26 06:12:33
【问题描述】:

存储库:https://github.com/patsevanton/ansible-role-patroni-question 库存:

[all]
node1 ansible_host=192.168.88.95
node2 ansible_host=192.168.88.96
node3 ansible_host=192.168.88.97

[patroni]
node1
node2
node3

默认主 yaml 文件 https://github.com/patsevanton/ansible-role-patroni-question/blob/master/defaults/main.yml#L115

如何将 ip 节点从库存设置为 default/main.yaml ? 这不是模板!这是默认/main.yaml。

【问题讨论】:

    标签: ansible


    【解决方案1】:

    它在defaults 中代表该角色这一事实意味着它设计可以被您覆盖。

    因此:

    - hosts: patroni
      roles:
      - patsevanton.patroni-question
        vars:
          patroni_bootstrap_pg_hba: >-
            [
            {%- set thing = { "type": "host", "database": "replication", "user": patroni_replication_username, "method": "md5" } -%}
            {%- for h, v in dict(hostvars).items() -%}
            {%- set _ = thing.update({"address": v.ansible_host}) -%}
            {{ "" if loop.first else "," }}
            {{ thing | to_json }}
            {%- endfor -%}
            ]
    

    pg_hba 定义拉到角色之外意味着您现在也必须指定replication_username,因为外部剧本不能(轻松)查看角色以获取现有默认值。 C'est la vie 使用默认设计不佳的角色时。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-28
      • 2019-11-11
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      • 2016-01-21
      • 2022-01-23
      相关资源
      最近更新 更多