Initial commit
[ta/infra-ansible.git] / roles / manage_user / tasks / main.yml
1 # Copyright 2019 Nokia
2
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
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 ---
16 - name: "create or delete chroot user"
17   user:
18     name: "{{ item.name }}"
19     groups: "{{ item.group }}"
20     password: "{{ item.password | default('')}}"
21     remove: "{{ item.remove | default('yes')}}"
22     state: "{{ item.state | default('absent')}}"
23     system: no
24     shell: /bin/nologin
25     createhome: no
26   with_items: "{{ chroot | default([]) }}"
27
28 - name: "Create the ssh-keys directory"
29   file:
30     path: /etc/ssh-keys
31     state: directory
32
33 - name: "remove the old public ssh key"
34   file:
35     path: /etc/ssh-keys/{{ item.name }}
36     state: absent
37   with_items: "{{ chroot | default([]) }}"
38
39 - name: "add a new public ssh key"
40   when: item.state == 'present'
41   lineinfile:
42     path: /etc/ssh-keys/{{ item.name }}
43     create: yes
44     regexp: '.*'
45     state: "{{ item.state | default('absent') }}"
46     line: "{{ item.public_key }}"
47     owner: "{{ item.name }}"
48     mode: 0400
49   with_items: "{{ chroot | default([]) }}"
50
51 - name: Locking and Unlocking the user
52   when: item.state == 'present' and item.password != ""
53   command: sudo passwd "{{ item.name }}" "{{ item.lock_state }}"
54   with_items: "{{ chroot | default([]) }}"