以下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和连接小瓶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时,只使用库存操作系统映像…
我使用的是
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