]> git.somenet.org - root/pub/somesible.git/blob - roles/base/create-users/tasks/setup-user.yml
roles/base/backup/files
[root/pub/somesible.git] / roles / base / create-users / tasks / setup-user.yml
1 #####################################
2 ### someone's ansible provisioner ###
3 #####################################
4 # Part of: https://git.somenet.org/root/pub/somesible.git
5 # 2017-2024 by someone <someone@somenet.org>
6 #
7 ---
8 - name: create {{user.name}} user
9   user:
10     name: "{{user.name}}"
11     home: "{{user.home | default ('/home/'+user.name)}}"
12     shell: "{{user.shell | default ('/bin/bash')}}"
13     groups: "{{user.groups | default ('')}}"
14     append: yes
15     createhome: no
16     state: present
17
18
19 - name: create {{user.name}} user's homedir
20   file:
21     path: "{{user.home | default ('/home/'+user.name)}}"
22     state: directory
23     mode: "{{user.homemode | default ('0750')}}"
24     owner: "{{user.name}}"
25     group: "{{user.name}}"
26
27
28 - name: copy {{user.name}}'s .profile
29   copy:
30     src: "{{item}}"
31     dest: "{{user.home | default ('/home/'+user.name)}}/.profile"
32     force: "{{user.force | default ('no')}}"
33     mode: 0755
34     owner: "{{user.name}}"
35     group: "{{user.name}}"
36   with_first_found:
37     - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/{{user.name}}/profile"
38     - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/{{user.name}}/profile"
39     - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/{{user.name}}/profile"
40     - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/profile"
41     - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/profile"
42     - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/profile"
43     - "default/profile"
44
45
46 - name: symlink {{user.name}}'s .zprofile to .profile
47   file:
48     src: "{{user.home | default ('/home/'+user.name)}}/.profile"
49     dest: "{{user.home | default ('/home/'+user.name)}}/.zshrc"
50     force: "{{user.force | default ('no')}}"
51     mode: 0755
52     owner: "{{user.name}}"
53     group: "{{user.name}}"
54     state: link
55   ignore_errors: yes
56
57
58 - name: create {{user.name}}'s .ssh dir
59   file:
60     path: "{{user.home | default ('/home/'+user.name)}}/.ssh"
61     state: directory
62     mode: 0700
63     owner: "{{user.name}}"
64     group: "{{user.name}}"
65
66
67 - name: copy {{user.name}}'s .ssh/config
68   copy:
69     src: "{{item}}"
70     dest: "{{user.home | default ('/home/'+user.name)}}/.ssh/config"
71     force: "{{user.force | default ('no')}}"
72     mode: 0600
73     owner: "{{user.name}}"
74     group: "{{user.name}}"
75   with_first_found:
76     - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/{{user.name}}/ssh_config"
77     - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/{{user.name}}/ssh_config"
78     - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/{{user.name}}/ssh_config"
79     - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/ssh_config"
80     - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/ssh_config"
81     - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/ssh_config"
82     - "default/ssh_config"
83
84
85 - name: copy {{user.name}}'s authorized_keys
86   copy:
87     src: "{{item}}"
88     dest: "{{user.home | default ('/home/'+user.name)}}/.ssh/authorized_keys"
89     force: "{{user.force | default ('no')}}"
90     mode: 0600
91     owner: "{{user.name}}"
92     group: "{{user.name}}"
93   with_first_found:
94     - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/{{user.name}}/authorized_keys"
95     - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/{{user.name}}/authorized_keys"
96     - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/{{user.name}}/authorized_keys"
97     - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/authorized_keys"
98     - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/authorized_keys"
99     - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/authorized_keys"
100     - "default/authorized_keys"