大网数据广告活动
服务器运维问答

Use ansible initialize postgresql multiple times

· 52CE 我爱测

Make this task will work the first time: - name: Initialize the Database command: /usr/pgsql-9.6/bin/postgresql96-setup initdb If run it a second time, will get the error: fatal: [192.168.0.1]: FAILED! => {"changed": true, "cmd":…

问题原文

原帖链接 · rawmain · CC BY-SA 4.0

Make this task will work the first time:

- name: Initialize the Database
  command: /usr/pgsql-9.6/bin/postgresql96-setup initdb

If run it a second time, will get the error:

fatal: [192.168.0.1]: FAILED! => {"changed": true, "cmd": ["/usr/pgsql-9.6/bin/postgresql96-setup", "initdb"], "delta": "0:00:00.017590", "end": "2019-12-11 06:08:49.999631", "msg": "non-zero return code", "rc": 1, "start": "2019-12-11 06:08:49.982041", "stderr": "", "stderr_lines": [], "stdout": "Data directory is not empty!", "stdout_lines": ["Data directory is not empty!"]}

How to avoid running this task if it already initialized the database on the server?

已采纳解答

原帖链接 · dmourati · CC BY-SA 4.0

Check to see if the file/directory created by initdb is there first and if not, initdb.

https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。