PostgreSQL端口还没有为ansible任务做好准备

时间:2018-06-10 13:45:43

标签: postgresql ansible

我几乎完成了主节点和从节点之间PostgreSQL HA Ansible角色的设置,但它仍然失败了一个命令:

- name: Create base backup
  command: pg_basebackup -X stream -D {{ postgres_home }} -h {{ master_ip }} -U {{ replica_user }}
  become: yes
  become_user: postgres

Ansible的错误输出:

"stderr": "pg_basebackup: could not connect to server: could not connect to server: Connection refused\n\tIs the server running on host \"10.44.164.159\" and accepting\n\tTCP/IP connections on port 5432?",
    "stderr_lines": [
        "pg_basebackup: could not connect to server: could not connect to server: Connection refused",
        "\tIs the server running on host \"10.44.164.159\" and accepting",
        "\tTCP/IP connections on port 5432?"

但是当我在播放器失败后运行此命令时,它运行时没有任何错误并且成功。

为什么没有Ansible而不在角色和剧本中?

谢谢!

1 个答案:

答案 0 :(得分:2)

您需要在此任务之前添加任务以等待postgresql服务器准备就绪。

你可以这样做

- name: hold until Postgresql is up and running
  wait_for:
    host "{{ master_ip }}"
    port: 5432

您还可以查看完整的文档here