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

时间:2014-01-23 19:14:39

标签: postgresql ansible

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

- name: ensure database is created
  postgresql_db: name={{dbname}}
  sudo_user: postgres

任务在失败前暂停几分钟 流浪汉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

我已经确认postgres已正确安装 通过做vagrant ssh并连接vial psql。

我还验证了我可以在VM中执行“sudo su postgres”...

========更新

看起来问题是sudo_user:postgres,因为删除了 在postgres任务之上,用这个替换会导致同样的问题:

- name: say hello from postgress
  command: echo "hello"
  sudo_user: postgres

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

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

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

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

但是psql shell仍然成功启动

========结论

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

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

1 个答案:

答案 0 :(得分:0)

我正在使用wait for主持人:

- local_action: wait_for port=22 host="{{PosgresHost}}" search_regex=OpenSSH delay=1 timeout=60
  ignore_errors: yes

PS:

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

---
- name: Setup
  hosts: all
  #connection: local
  user: root
  gather_facts: False
  roles:
    - main

示例角色/ 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

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