我在Raspberry Pi上运行了Kodi,我正在写一本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
答案 0 :(得分:2)
我认为您可能会遇到pull request #6652
中描述的内容将visudo
中的validate
替换为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
验证(未找到)。