2024-06-24 13:52:54 发布
网友
在documentation中,有一个使用lineinfile模块编辑/etc/sudoers的示例。
lineinfile
/etc/sudoers
- lineinfile: "dest=/etc/sudoers state=present regexp='^%wheel' line='%wheel ALL=(ALL) NOPASSWD: ALL'"
感觉有点老土。
我以为user模块中会有一些东西来处理这个问题,但似乎没有任何选项。
user
在/etc/sudoers中添加和删除用户的最佳实践是什么?
这一行实际上并没有向sudoers添加用户,只是确保wheel组可以使用password sudo for all命令。
wheel
至于将用户添加到/etc/sudoers中,最好将用户添加到必要的组中,然后为这些组提供sudo的相关访问权限。当你不使用Ansible的时候,这也是正确的。
user module允许您指定组的独占列表,或者只需将指定的组附加到用户已经拥有的当前组。这自然是等幂的,因为用户不能多次定义为在一个组中。
一个例子可能是这样的:
- hosts: all vars: sudoers: - user1 - user2 - user3 tasks: - name: Make sure we have a 'wheel' group group: name: wheel state: present - name: Allow 'wheel' group to have passwordless sudo lineinfile: dest: /etc/sudoers state: present regexp: '^%wheel' line: '%wheel ALL=(ALL) NOPASSWD: ALL' validate: visudo -cf %s - name: Add sudoers users to wheel group user: name: "{{ item }}" groups: wheel append: yes with_items: "{{ sudoers }}"
这一行实际上并没有向sudoers添加用户,只是确保
wheel
组可以使用password sudo for all命令。至于将用户添加到
/etc/sudoers
中,最好将用户添加到必要的组中,然后为这些组提供sudo的相关访问权限。当你不使用Ansible的时候,这也是正确的。user module允许您指定组的独占列表,或者只需将指定的组附加到用户已经拥有的当前组。这自然是等幂的,因为用户不能多次定义为在一个组中。
一个例子可能是这样的:
相关问题 更多 >
编程相关推荐