在Ansible上,如何根据hostservice使用不同的postgresql.conf文件?

问题描述 投票:1回答:1

我正在运行两台不同的服务器,每台服务器都有不同的用例,以备不时之需。postgres因此,我想让每个 postgres 服务运行在不同的配置上(定义在 postgresql.conf).

目前ansible对postgresql的设置如下,其中postgresql是一个 role:

postgresql
├── handlers
│   └── main.yml
├── tasks
│   └── main.yml
└── templates
    ├── pg_hba.conf
    └── postgresql.conf

我的目标是了解这样做的最佳做法是什么,而不必给不同的名称。postgresql.conf 文件(如果可能的话).我正在运行两台不同的服务器,每台服务器都有不同的postgres使用案例,因此我想让每个postgres服务运行在不同的配置上(在postgresql.conf中定义)。

postgresql ansible ansible-inventory
1个回答
0
投票

你可以在清单中定义需要使用的文件,这样。

all:
  children:
    postgress:
      hosts:
        host1:
          postgress_conf: postgresql.conf
        host2:
          postgress_conf: pg_hba.conf

然后使用剧本中的变量 copy 任务。

- hosts: postgress

  tasks:
    - copy:
        src: templates/{{ postgress_conf }}
        dest: /etc/postgresql/x.x/main/postgresql.conf
© www.soinside.com 2019 - 2024. All rights reserved.