在我的角色中,我有一个任务要尝试安装Jenkins rpm。 rpm位于目标主机上的/ tmp目录中。另外,我有权运行命令``sudo / bin / rpm -Uvh /tmp/jenkins-2.107.1.2-1.1.noarch.rpm'',该命令在我尝试直接在服务器上运行时有效。但是通过命令模块运行同一命令会失败。
任务:
- name: run the rpm command on masters
command: sudo /bin/rpm -Uvh jenkins-2.107.1.2-1.1.noarch.rpm
args:
chdir: /tmp
错误:
fatal: [xxxx. xxx.com]: FAILED! => {"changed": false, "cmd": "'sudo rpm' -Uvh 'jenkins-2.107.1.2-1.1.noarch.rpm'", "msg": "[Errno 2] No such file or directory", "rc": 2}
对目标主机的权限:
User XXXX may run the following commands on target_Host_Name:
(root) NOPASSWD: /usr/sbin/service jenkins stop, /usr/sbin/service jenkins start, /bin/rpm -Uvh jenkins*.noarch.rpm
答案 0 :(得分:1)
例如,您可以将ansible
的{{1}} yum
模块与become: true
的{{1}}模块一起使用,例如:
command
注意:错误sudo
是明确的,文件- name: install jenkins rpm from a local file
yum:
name: /tmp/jenkins-2.107.1.2-1.1.noarch.rpm
state: present
become: true
不存在。在尝试安装[Errno 2] No such file or directory
之前,您需要确保该文件存在。
有关/tmp/jenkins-2.107.1.2-1.1.noarch.rpm
中特权升级的其他信息,请参见:https://docs.ansible.com/ansible/latest/user_guide/become.html