3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 - name: "create or delete linux user"
18 name: "{{ item.name }}"
19 password: "{{ item.password | default('') }}"
20 remove: "{{ item.remove | default('yes') }}"
21 force: "{{ item.remove | default('yes') }}"
22 state: "{{ item.state | default('absent') }}"
23 with_items: "{{ linuxuser | default([]) }}"
25 - name: "remove the old public ssh key"
27 path: /home/{{ item.name }}/.ssh/{{ item.name }}
29 with_items: "{{ linuxuser | default([]) }}"
31 - name: "Create the user .ssh directory"
32 when: item.state == 'present'
34 path: /home/{{ item.name }}/.ssh
36 owner: "{{ item.name }}"
37 group: "{{ item.name }}"
39 with_items: "{{ linuxuser | default([]) }}"
41 - name: "add a new public ssh key"
42 when: item.state == 'present' and item.public_key != ""
44 path: /home/{{ item.name }}/.ssh/{{ item.name }}
47 state: "{{ item.state | default('absent') }}"
48 line: "{{ item.public_key | default('') }}"
49 group: "{{ item.name }}"
50 owner: "{{ item.name }}"
52 with_items: "{{ linuxuser | default([]) }}"
54 - name: Locking and Unlocking the user
55 when: item.state == 'present' and item.password != ""
56 command: sudo passwd "{{ item.name }}" "{{ item.lock_state }}"
57 with_items: "{{ linuxuser | default([]) }}"