ansible sudo_用户挂起几分钟,然后失败(在centos6.5.1 vagrant vm中)
我有两个简单的任务:ansible sudo_用户挂起几分钟,然后失败(在centos6.5.1 vagrant vm中),vagrant,ansible,Vagrant,Ansible,我有两个简单的任务: - name: I am shell: "echo `id`" - name: say hello shell: echo "postgres saying hello" sudo_user: postgres 第二个任务在长时间暂停后失败,输出如下 (它与vvv级别的流浪汉一起运行) (是的,我已验证用户postgres是否存在, 我可以在虚拟机内完成sudo su postgres) 这个东西在centos6.5.1流浪vm中运行它显然不适用于cent
- name: I am
shell: "echo `id`"
- name: say hello
shell: echo "postgres saying hello"
sudo_user: postgres
第二个任务在长时间暂停后失败,输出如下
(它与vvv级别的流浪汉一起运行)
(是的,我已验证用户postgres是否存在,
我可以在虚拟机内完成sudo su postgres)
这个东西在centos6.5.1流浪vm中运行它显然不适用于centos6.5。假设它无法通过postgres系统用户密码提示,尽管这是推测 对于如何克服ansible to sudo to postgres(这反过来将通过默认的pg_hba.conf配置使用对等身份验证)在postgresql_*命令期间无法执行的问题,这里有一个解决方法:
- hosts: all
sudo: yes
gather_facts: no
tasks:
- lineinfile: dest='/var/lib/pgsql/9.3/data/pg_hba.conf' regexp="^local\s+all\s+all\s+peer$" line="local all all trust" backrefs=yes
- name: restart after line change
action: shell sudo /etc/init.d/postgresql-9.3 restart
- name: create database
postgresql_db: name=acme
sudo: no # NB!!
sudo_user: postgres
我们正在将本地访问权限从peer
更改为trust
,需要在另一个lineinfle
执行所需操作或使用md5替换文件或任何所需配置后重新启动后删除。上述内容显然仅供演示。这是一个大规模的黑客攻击,但允许您发出在Centos6下工作的ansible postgresql模块命令。请注意,我们为postgresql任务设置了sudo
我确认了问题的存在,并对这个虚拟机框进行了破解:
https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
问题可能在sudoers配置中。我遇到了一个与Debian 7.6中的问题相同的问题,该问题在
/etc/sudoers
中有以下行:
%sudo ALL=(ALL:ALL) NOPASSWD: ALL
在我将该行更改为以下内容之后:
%sudo ALL=(ALL) NOPASSWD: ALL
Ansible开始按预期工作,即它能够以
postgres
用户的身份使用sudo
执行任务,但我不确定,但我认为在“打招呼”操作中还需要一个“sudo:True”。
%sudo ALL=(ALL) NOPASSWD: ALL