我不能将用户添加到多个组,我不断收到消息:此模块需要key = value参数。
这是我想要的一段代码:
- name: make a new user user: name=user state=present groups="group1", "group2", "group3" comment="comment"
该文档说:组= =用户在这个逗号分隔的组列表。 当设置为空string('groups =')时,用户将从除主组以外的所有组中移除。
我尝试过“群”,“群”,没有冒号,仍然得到同样的错误。
http://docs.ansible.com/user_module.html
正确的语法是:
- name: make a new user user: name=user state=present groups="group1, group2, group3" comment="comment"
您发布的代码有两个问题:
groups ,请使用以逗号分隔的值,其间不要有空格: groups: group1,group2 = for : 这是一个工作代码的例子:
- name: make a new user user: name: johnsmith state: present groups: group1,group2 comment: "comment" append: no # If yes, will only add groups, not set them to just the list in groups.
我得到组“group2”不存在。 (但没有引号,这是显示额外的空间)。
正确的方法是
groups={{ group }},{{ sudo_group }}
上面的答案是不正确的。 定义variables的正确方法是:
groups: group1,group2
然后使用:
action: user groups={{user.groups}}