经过很长时间的停顿后,Ansible postgresql_db任务失败

Max*_* L. 8 postgresql ansible

以下ansible任务(在vagrant VM中)失败:

- name: ensure database is created
  postgresql_db: name={{dbname}}
  sudo_user: postgres
Run Code Online (Sandbox Code Playgroud)

任务暂停几分钟,然后流浪汉VM失败是centos6.5.1,任务输出是:

TASK: [postgresql | ensure database is created] ******************************* 
fatal: [192.168.78.6] => failed to parse: 
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo via ansible, key=glxzviadepqkwddapvjheeuillbdakly] password: 


FATAL: all hosts have already failed -- aborting
Run Code Online (Sandbox Code Playgroud)

我已经验证了postgres是通过做vagrant ssh和连接vial psql而正确安装的.

我也验证了我可以在VM中做一个"sudo su postgres"...

========更新

看起来问题是sudo_user:postgres,因为删除上面的postgres任务并替换为这个导致同样的问题:

- name: say hello from postgress
  command: echo "hello"
  sudo_user: postgres
Run Code Online (Sandbox Code Playgroud)

输出与上面完全相同,所以它确实是ansible在centos6.5上做sudo_user的问题

一个有趣的观察,虽然我可以从vm里面做"sudo su postgres"

当我调用"psql"(作为postgres用户)时,我收到消息:

无法将目录更改为"/ home/vagrant":权限被拒绝

但psql shell仍然成功启动

========结论

通过更改为库存中心框来解决问题,

经验教训:使用ansible/vagrant时,只使用库存操作系统映像...

Val*_*yov 0

我正在使用等待主机:

- local_action: wait_for port=22 host="{{PosgresHost}}" search_regex=OpenSSH delay=1 timeout=60
  ignore_errors: yes
Run Code Online (Sandbox Code Playgroud)

附:

我认为你应该使用 Gather_facts: False 并在 ssh 启动后进行设置。示例 main.yml:

---
- name: Setup
  hosts: all
  #connection: local
  user: root
  gather_facts: False
  roles:
    - main
Run Code Online (Sandbox Code Playgroud)

示例角色/main/tasks/main.yml

- debug: msg="System {{ inventory_hostname }} "
- local_action: wait_for port=22 host="{{ inventory_hostname}}" search_regex=OpenSSH delay=1 timeout=60
  ignore_errors: yes
- action: setup
Run Code Online (Sandbox Code Playgroud)

ansible-playbook -i 127.0.0.1,main.yml

PLAY [Setup] ******************************************************************

TASK: [main | debug msg="System {{ inventory_hostname }} "] *******************
ok: [127.0.0.1] => {
    "msg": "System 127.0.0.1 "
}

TASK: [main | wait_for port=22 host="{{ inventory_hostname}}" search_regex=OpenSSH delay=1 timeout=60] ***
ok: [127.0.0.1 -> 127.0.0.1]

PLAY RECAP ********************************************************************
127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0
Run Code Online (Sandbox Code Playgroud)