내가 알 수있는 한, 일반 사용자 모듈만으로는 할 수 없습니다.
그러나 꽤 복잡한 미션을 사용하면 게임 플레이에서 할 수 있습니다. 그래도 나는 이것을 추천하지 않는다. 그것은 단지 흥미로운 운동이었습니다. (나는 이것을 시험해 보았다.)
재미있는 부분은 "새 그룹 목록 작성"작업으로 목록 항목을 제거합니다. python 목록에서 .remove()를 호출하면 새 목록이 반환되며, 이는 모두 불필요한 것입니다. 기능
---
- hosts: target
gather_facts: no
vars:
group_to_remove: admins
new_groups_list: []
user_to_check: user1
tasks:
- user: name="{{ user_to_check }}" groups=testers,developers,admins
- name: get the current groups list
command: groups "{{ user_to_check }}"
register: current_groups
- debug: var=current_groups
# parse the output of the groups command into a python list
# of the current groups
- set_fact:
current_group_list: "{{ current_groups.stdout.replace(user_to_check+' : ','').split(' ') }}"
- name: show user_group_list
debug: var=current_group_list
- name: build the new groups list
set_fact:
new_groups_list: "{{ new_groups_list + [ item ] }}"
no_log: False
when: "not '{{ group_to_remove }}' == '{{ item }}'"
with_items: "{{ current_group_list }}"
# turn the list, into a comma-delimited string
- set_fact:
new_groups: "{{ ','.join(new_groups_list) }}"
- name: show new_groups_list
debug: var=new_groups
- name: set new user groups
user: name="{{ user_to_check }}" groups="{{ new_groups }}"
- name: get the new groups list
command: groups "{{ user_to_check }}"
register: new_groups
- debug: var=new_groups