ansible 在 "sudo yum install"' 步骤中挂起
ansible hangs in "sudo yum install"' step
我正在尝试设置 ansible (2.0) 以便在 linux 盒子上安装软件
ies-iesd-jktools
是ansible的机器。 ies-iesd-git-06
是目标。用户帐户是 iesdgrid
,可以在目标机器上执行 sudo。
以下命令在远程挂起:-
ies-iesd-jktools:~/ansible$ ansible ies-iesd-git-06 \
-i inventory -m raw \
-a "sudo yum install -y python-simplejson" -vvvv
Using /usr/src/ansible/ansible.cfg as config file
SUDO password: <I type password here>
Loaded callback minimal of type stdout, v2.0
<ies-iesd-git-06> ESTABLISH CONNECTION FOR USER: None on PORT 22 TO ies-iesd-git-06
<ies-iesd-git-06> EXEC sudo yum install -y python-simplejson
这会在目标机器上启动一个 sudo,但不会像等待密码那样继续进行
$ hostname
ies-iesd-git-06
$
$ ps -ef| grep su
root 583 582 0 09:01 pts/1 00:00:00 sudo yum install -y python-simplejson
iesdgrid 811 771 0 09:05 pts/2 00:00:00 grep su
哪里出错了?
过了一会儿我得到了
sudo: pam_authenticate: Conversation error
(手动登录到目标机器,然后 sudo 就可以了。)
sudo
在设计上需要交互式 shell 以便输入密码。
完全自动调用 sudo 的最简单方法是让用户 NOPASSWD
访问所有或仅必要的命令,尽管这可能会带来安全风险。
有关 /etc/sudoers
配置文件的详细信息,请参见 http://www.sudo.ws/man/1.8.15/sudoers.man.html。
stackexchange 上有几个线程处理 linux 上自动提升执行的问题:
- Specify sudo password for Ansible
- https://unix.stackexchange.com/questions/69172/how-to-securely-automate-running-commands-as-root-with-sudo-su
- https://unix.stackexchange.com/questions/144997/sudo-su-automated-login
- https://superuser.com/questions/243499/automating-the-sudo-su-user-command
- Automating password into sudo
您需要指定 --become
--become-user root
--ask-become-pass
参数,以便 ansible 会在执行命令之前 sudo su 到 root。
ansible -m raw -a "yum install python-simplejson" testserver --ask-become-pass --become-user root --become
SUDO password:
testserver | SUCCESS | rc=0 >>
Loaded plugins: security
Setting up Install Process
Static_ol6_UEK2_latest | 2.3 kB 00:00
Static_ol6_latest | 2.3 kB 00:00
Package python-simplejson-2.0.9-3.1.el6.x86_64 already installed and latest version
Nothing to do
我正在尝试设置 ansible (2.0) 以便在 linux 盒子上安装软件
ies-iesd-jktools
是ansible的机器。 ies-iesd-git-06
是目标。用户帐户是 iesdgrid
,可以在目标机器上执行 sudo。
以下命令在远程挂起:-
ies-iesd-jktools:~/ansible$ ansible ies-iesd-git-06 \
-i inventory -m raw \
-a "sudo yum install -y python-simplejson" -vvvv
Using /usr/src/ansible/ansible.cfg as config file
SUDO password: <I type password here>
Loaded callback minimal of type stdout, v2.0
<ies-iesd-git-06> ESTABLISH CONNECTION FOR USER: None on PORT 22 TO ies-iesd-git-06
<ies-iesd-git-06> EXEC sudo yum install -y python-simplejson
这会在目标机器上启动一个 sudo,但不会像等待密码那样继续进行
$ hostname
ies-iesd-git-06
$
$ ps -ef| grep su
root 583 582 0 09:01 pts/1 00:00:00 sudo yum install -y python-simplejson
iesdgrid 811 771 0 09:05 pts/2 00:00:00 grep su
哪里出错了?
过了一会儿我得到了
sudo: pam_authenticate: Conversation error
(手动登录到目标机器,然后 sudo 就可以了。)
sudo
在设计上需要交互式 shell 以便输入密码。
完全自动调用 sudo 的最简单方法是让用户 NOPASSWD
访问所有或仅必要的命令,尽管这可能会带来安全风险。
有关 /etc/sudoers
配置文件的详细信息,请参见 http://www.sudo.ws/man/1.8.15/sudoers.man.html。
stackexchange 上有几个线程处理 linux 上自动提升执行的问题:
- Specify sudo password for Ansible
- https://unix.stackexchange.com/questions/69172/how-to-securely-automate-running-commands-as-root-with-sudo-su
- https://unix.stackexchange.com/questions/144997/sudo-su-automated-login
- https://superuser.com/questions/243499/automating-the-sudo-su-user-command
- Automating password into sudo
您需要指定 --become
--become-user root
--ask-become-pass
参数,以便 ansible 会在执行命令之前 sudo su 到 root。
ansible -m raw -a "yum install python-simplejson" testserver --ask-become-pass --become-user root --become
SUDO password:
testserver | SUCCESS | rc=0 >>
Loaded plugins: security
Setting up Install Process
Static_ol6_UEK2_latest | 2.3 kB 00:00
Static_ol6_latest | 2.3 kB 00:00
Package python-simplejson-2.0.9-3.1.el6.x86_64 already installed and latest version
Nothing to do