我让 Kodi 在 Raspberry Pi 上运行,我正在为此编写一本 Ansible 剧本。这个剧本包括两个任务,用于检查一条线是否存在于/etc/sudoers
,一个持续通过,另一个持续失败。我似乎无法确定原因;两个任务的语法完全相同,两行肯定都在/etc/sudoers
文件中。我在下面包含了相关的代码,任何输入将不胜感激。
/etc/sudoers
:
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
# Host alias specification
# User alias specification
# Cmnd alias specification
Cmnd_Alias SHUTDOWN = /sbin/shutdown, /sbin/reboot, /sbin/halt, /usr/bin/passwd
Cmnd_Alias PERMISSIONS = /bin/chmod, /bin/chown
# User privilege specification
root ALL=(ALL) ALL
pi ALL=(ALL) NOPASSWD: ALL
debian-transmission ALL=(ALL) NOPASSWD: PERMISSIONS
Defaults env_keep += "RPI_UPDATE_UNSUPPORTED"
# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d
剧本任务中的相关代码段:
- name: set pi permissions in /etc/sudoers
lineinfile: "dest=/etc/sudoers
state=present
line='pi ALL=(ALL) NOPASSWD: ALL'
validate='visudo -cf %s'"
- name: set debian-transmission permissions in /etc/sudoers
lineinfile: "dest=/etc/sudoers
state=present
line='debian-transmission ALL=(ALL) NOPASSWD: PERMISSIONS'
validate='visudo -cf %s'"
(我知道第一个任务是不必要的,因为这是系统默认值,但我在试图弄清楚为什么另一个任务不起作用只是为了证明一个观点时添加了它。
这是我运行剧本时的输出:
TASK: [kodi | start transmission-daemon again once settings.json has been copied] ***
changed: [kodi]
TASK: [kodi | set pi permissions in /etc/sudoers] *****************************
ok: [kodi]
TASK: [kodi | set debian-transmission permissions in /etc/sudoers] ************
failed: [kodi] => {"cmd": "visudo -cf /tmp/tmpZNRBC3", "failed": true, "rc": 2}
msg: [Errno 2] No such file or directory
FATAL: all hosts have already failed -- aborting
我想您可能正在经历拉取请求 #6652 中描述的内容
将validate
中的visudo
替换为visudo
的完整路径,它应该可以工作。
- name: set debian-transmission permissions in /etc/sudoers
lineinfile: "dest=/etc/sudoers
state=present
line='debian-transmission ALL=(ALL) NOPASSWD: PERMISSIONS'
validate='/usr/sbin/visudo -cf %s'"
您的第一个任务(具有pi
用户权限)有效,因为所需的行已在文件中,并且不需要使用 visudo
进行验证。但是,必须添加带有debian-transmission
的行并经过visudo
验证(未找到)。