From 79fc7e94fc1d14c0308b0bc0998b4de8607ac719 Mon Sep 17 00:00:00 2001 From: Vincent Lafeychine Date: Sun, 8 Oct 2023 13:15:03 +0200 Subject: [PATCH 1/5] chore: Extract account handling from common role --- common.yml | 1 + roles/common/tasks/main.yml | 139 ----------------------------------- roles/users/tasks/main.yml | 140 ++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 139 deletions(-) create mode 100644 roles/users/tasks/main.yml diff --git a/common.yml b/common.yml index 5eed2f88..44fb5027 100644 --- a/common.yml +++ b/common.yml @@ -4,3 +4,4 @@ become: yes roles: - common + - users diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index eaf5fb00..de032955 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -401,145 +401,6 @@ - /data/project - /data/work -- include: ../../../shared/account.yml user=cquest uid=1202 -- include: ../../../shared/account.yml user=jocelyn uid=1203 -- include: ../../../shared/account.yml user=marc_marc uid=1216 - -- include: ../../../shared/account.yml user=achetta uid=1236 - when: "'achetta' in group_names" - -- include: ../../../shared/account.yml user=apavie uid=1211 - when: "'apavie' in group_names" - -- include: ../../../shared/account.yml user=cgiquello uid=1212 - when: "'cgiquello' in group_names" - -- include: ../../../shared/account.yml user=cormoran uid=1219 - when: "'cormoran' in group_names" - -- include: ../../../shared/account.yml user=davidbgk uid=1251 - when: "'davidbgk' in group_names" - -- include: ../../../shared/account.yml user=don-vip uid=1247 - when: "'don-vip' in group_names" - -- include: ../../../shared/account.yml user=driss uid=1224 - when: "'driss' in group_names" - -- include: ../../../shared/account.yml user=etienne uid=1213 - when: "'etienne' in group_names" - -- include: ../../../shared/account.yml user=eloks uid=1214 - when: "'eloks' in group_names" - -- include: ../../../shared/account.yml user=famlam uid=1250 - when: "'famlam' in group_names" - -- include: ../../../shared/account.yml user=flacombe uid=1246 - when: "'flacombe' in group_names" - -- include: ../../../shared/account.yml user=francois2 uid=1221 - when: "'francois2' in group_names" - -- include: ../../../shared/account.yml user=fred uid=1205 - when: "'fred' in group_names" - -- include: ../../../shared/account.yml user=gileri uid=1311 - when: "'gileri' in group_names" - -- include: ../../../shared/account.yml user=guillaumeamat uid=1235 - when: "'guillaumeamat' in group_names" - -- include: ../../../shared/account.yml user=gpelloux uid=1237 - when: "'gpelloux' in group_names" - -- include: ../../../shared/account.yml user=hamlet uid=1305 - when: "'hamlet' in group_names" - -- include: ../../../shared/account.yml user=jacques uid=1306 - when: "'jacques' in group_names" - -- include: ../../../shared/account.yml user=jben uid=1206 - when: "'jben' in group_names" - -- include: ../../../shared/account.yml user=jgcailton uid=1207 - when: "'jgcailton' in group_names" - -- include: ../../../shared/account.yml user=juliep uid=1210 - when: "'juliep' in group_names" - -- include: ../../../shared/account.yml user=karl uid=1238 - when: "'karl' in group_names" - -- include: ../../../shared/account.yml user=lcombe uid=1215 - when: "'lcombe' in group_names" - -- include: ../../../shared/account.yml user=ljbouere uid=1248 - when: "'ljbouere' in group_names" - -- include: ../../../shared/account.yml user=mael uid=1218 - when: "'mael' in group_names" - -- include: ../../../shared/account.yml user=nlehuby uid=1220 - when: "'nlehuby' in group_names" - -- include: ../../../shared/account.yml user=nmoyroud uid=1226 - when: "'nmoyroud' in group_names" - -- include: ../../../shared/account.yml user=panieravide uid=1230 - when: "'panieravide' in group_names" - -- include: ../../../shared/account.yml user=phyks uid=1233 - when: "'phyks' in group_names" - -- include: ../../../shared/account.yml user=pyrog uid=1333 - when: "'pyrog' in group_names" - -- include: ../../../shared/account.yml user=redfox uid=1209 - when: "'redfox' in group_names" - -- include: ../../../shared/account.yml user=rodolphe uid=1208 - when: "'rodolphe' in group_names" - -- include: ../../../shared/account.yml user=rvoirin uid=1308 - when: "'rvoirin' in group_names" - -- include: ../../../shared/account.yml user=sly uid=1209 - when: "'sly' in group_names" - -- include: ../../../shared/account.yml user=stephanec uid=1225 - when: "'stephanec' in group_names" - -- include: ../../../shared/account.yml user=teslix uid=1222 - when: "'teslix' in group_names" - -- include: ../../../shared/account.yml user=thomasg77 uid=1249 - when: "'thomasg77' in group_names" - -- include: ../../../shared/account.yml user=thomasl uid=1210 - when: "'thomasl' in group_names" - -- include: ../../../shared/account.yml user=thorieux uid=1229 - when: "'thorieux' in group_names" - -- include: ../../../shared/account.yml user=thrrp uid=1310 - when: "'thrrp' in group_names" - -- include: ../../../shared/account.yml user=tykayn uid=1312 - when: "'tykayn' in group_names" - -- include: ../../../shared/account.yml user=tyndare uid=1212 - when: "'tyndare' in group_names" - -- include: ../../../shared/account.yml user=vdct uid=1217 - when: "'vdct' in group_names" - -- include: ../../../shared/account.yml user=ybon uid=1223 - when: "'ybon' in group_names" - -- include: ../../../shared/account.yml user=ydel uid=1313 - when: "'ydel' in group_names" - - name: add default sudoers copy: src: sudoers diff --git a/roles/users/tasks/main.yml b/roles/users/tasks/main.yml new file mode 100644 index 00000000..8c4307b1 --- /dev/null +++ b/roles/users/tasks/main.yml @@ -0,0 +1,140 @@ +--- +- include: ../../../shared/account.yml user=cquest uid=1202 +- include: ../../../shared/account.yml user=jocelyn uid=1203 +- include: ../../../shared/account.yml user=marc_marc uid=1216 + +- include: ../../../shared/account.yml user=achetta uid=1236 + when: "'achetta' in group_names" + +- include: ../../../shared/account.yml user=apavie uid=1211 + when: "'apavie' in group_names" + +- include: ../../../shared/account.yml user=cgiquello uid=1212 + when: "'cgiquello' in group_names" + +- include: ../../../shared/account.yml user=cormoran uid=1219 + when: "'cormoran' in group_names" + +- include: ../../../shared/account.yml user=davidbgk uid=1251 + when: "'davidbgk' in group_names" + +- include: ../../../shared/account.yml user=don-vip uid=1247 + when: "'don-vip' in group_names" + +- include: ../../../shared/account.yml user=driss uid=1224 + when: "'driss' in group_names" + +- include: ../../../shared/account.yml user=etienne uid=1213 + when: "'etienne' in group_names" + +- include: ../../../shared/account.yml user=eloks uid=1214 + when: "'eloks' in group_names" + +- include: ../../../shared/account.yml user=famlam uid=1250 + when: "'famlam' in group_names" + +- include: ../../../shared/account.yml user=flacombe uid=1246 + when: "'flacombe' in group_names" + +- include: ../../../shared/account.yml user=francois2 uid=1221 + when: "'francois2' in group_names" + +- include: ../../../shared/account.yml user=fred uid=1205 + when: "'fred' in group_names" + +- include: ../../../shared/account.yml user=gileri uid=1311 + when: "'gileri' in group_names" + +- include: ../../../shared/account.yml user=guillaumeamat uid=1235 + when: "'guillaumeamat' in group_names" + +- include: ../../../shared/account.yml user=gpelloux uid=1237 + when: "'gpelloux' in group_names" + +- include: ../../../shared/account.yml user=hamlet uid=1305 + when: "'hamlet' in group_names" + +- include: ../../../shared/account.yml user=jacques uid=1306 + when: "'jacques' in group_names" + +- include: ../../../shared/account.yml user=jben uid=1206 + when: "'jben' in group_names" + +- include: ../../../shared/account.yml user=jgcailton uid=1207 + when: "'jgcailton' in group_names" + +- include: ../../../shared/account.yml user=juliep uid=1210 + when: "'juliep' in group_names" + +- include: ../../../shared/account.yml user=karl uid=1238 + when: "'karl' in group_names" + +- include: ../../../shared/account.yml user=lcombe uid=1215 + when: "'lcombe' in group_names" + +- include: ../../../shared/account.yml user=ljbouere uid=1248 + when: "'ljbouere' in group_names" + +- include: ../../../shared/account.yml user=mael uid=1218 + when: "'mael' in group_names" + +- include: ../../../shared/account.yml user=nlehuby uid=1220 + when: "'nlehuby' in group_names" + +- include: ../../../shared/account.yml user=nmoyroud uid=1226 + when: "'nmoyroud' in group_names" + +- include: ../../../shared/account.yml user=panieravide uid=1230 + when: "'panieravide' in group_names" + +- include: ../../../shared/account.yml user=phyks uid=1233 + when: "'phyks' in group_names" + +- include: ../../../shared/account.yml user=pyrog uid=1333 + when: "'pyrog' in group_names" + +- include: ../../../shared/account.yml user=redfox uid=1209 + when: "'redfox' in group_names" + +- include: ../../../shared/account.yml user=rodolphe uid=1208 + when: "'rodolphe' in group_names" + +- include: ../../../shared/account.yml user=rvoirin uid=1308 + when: "'rvoirin' in group_names" + +- include: ../../../shared/account.yml user=sly uid=1209 + when: "'sly' in group_names" + +- include: ../../../shared/account.yml user=stephanec uid=1225 + when: "'stephanec' in group_names" + +- include: ../../../shared/account.yml user=teslix uid=1222 + when: "'teslix' in group_names" + +- include: ../../../shared/account.yml user=thomasg77 uid=1249 + when: "'thomasg77' in group_names" + +- include: ../../../shared/account.yml user=thomasl uid=1210 + when: "'thomasl' in group_names" + +- include: ../../../shared/account.yml user=thorieux uid=1229 + when: "'thorieux' in group_names" + +- include: ../../../shared/account.yml user=thrrp uid=1310 + when: "'thrrp' in group_names" + +- include: ../../../shared/account.yml user=tykayn uid=1312 + when: "'tykayn' in group_names" + +- include: ../../../shared/account.yml user=tyndare uid=1212 + when: "'tyndare' in group_names" + +- include: ../../../shared/account.yml user=vdct uid=1217 + when: "'vdct' in group_names" + +- include: ../../../shared/account.yml user=ybon uid=1223 + when: "'ybon' in group_names" + +- include: ../../../shared/account.yml user=ydel uid=1313 + when: "'ydel' in group_names" +... From e7c59d56e580406b09ef8de544d748529ebc20e4 Mon Sep 17 00:00:00 2001 From: Vincent Lafeychine Date: Sun, 8 Oct 2023 13:20:01 +0200 Subject: [PATCH 2/5] chore(role account): Using loop instead --- group_vars/all/users.yml | 149 ++++++++++++++++++++++++++++++++++ roles/users/defaults/main.yml | 3 + roles/users/tasks/main.yml | 142 +------------------------------- shared/account.yml | 8 +- 4 files changed, 162 insertions(+), 140 deletions(-) create mode 100644 group_vars/all/users.yml create mode 100644 roles/users/defaults/main.yml diff --git a/group_vars/all/users.yml b/group_vars/all/users.yml new file mode 100644 index 00000000..5c8c1f92 --- /dev/null +++ b/group_vars/all/users.yml @@ -0,0 +1,149 @@ +--- +users__accounts: + cquest: + uid: 1202 + admin: true + + jocelyn: + uid: 1203 + admin: true + + marc_marc: + uid: 1216 + admin: true + + achetta: + uid: 1236 + + apavie: + uid: 1211 + + cgiquello: + uid: 1212 + + cormoran: + uid: 1219 + + davidbgk: + uid: 1251 + + don-vip: + uid: 1247 + + driss: + uid: 1224 + + etienne: + uid: 1213 + + eloks: + uid: 1214 + + famlam: + uid: 1250 + + flacombe: + uid: 1246 + + francois2: + uid: 1221 + + fred: + uid: 1205 + + gileri: + uid: 1311 + + guillaumeamat: + uid: 1235 + + gpelloux: + uid: 1237 + + hamlet: + uid: 1305 + + jacques: + uid: 1306 + + jben: + uid: 1206 + + jgcailton: + uid: 1207 + + juliep: + uid: 1210 + + karl: + uid: 1238 + + lcombe: + uid: 1215 + + ljbouere: + uid: 1248 + + mael: + uid: 1218 + + nlehuby: + uid: 1220 + + nmoyroud: + uid: 1226 + + panieravide: + uid: 1230 + + phyks: + uid: 1233 + + pyrog: + uid: 1333 + + redfox: + uid: 1209 + + rodolphe: + uid: 1208 + + rvoirin: + uid: 1308 + + sly: + uid: 1209 + + stephanec: + uid: 1225 + + teslix: + uid: 1222 + + thomasg77: + uid: 1249 + + thomasl: + uid: 1210 + + thorieux: + uid: 1229 + + thrrp: + uid: 1310 + + tykayn: + uid: 1312 + + tyndare: + uid: 1212 + + vdct: + uid: 1217 + + ybon: + uid: 1223 + + ydel: + uid: 1313 +... diff --git a/roles/users/defaults/main.yml b/roles/users/defaults/main.yml new file mode 100644 index 00000000..38b5cc02 --- /dev/null +++ b/roles/users/defaults/main.yml @@ -0,0 +1,3 @@ +--- +users__accounts: {} +... diff --git a/roles/users/tasks/main.yml b/roles/users/tasks/main.yml index 8c4307b1..35c4096a 100644 --- a/roles/users/tasks/main.yml +++ b/roles/users/tasks/main.yml @@ -1,140 +1,6 @@ --- -- include: ../../../shared/account.yml user=cquest uid=1202 -- include: ../../../shared/account.yml user=jocelyn uid=1203 -- include: ../../../shared/account.yml user=marc_marc uid=1216 - -- include: ../../../shared/account.yml user=achetta uid=1236 - when: "'achetta' in group_names" - -- include: ../../../shared/account.yml user=apavie uid=1211 - when: "'apavie' in group_names" - -- include: ../../../shared/account.yml user=cgiquello uid=1212 - when: "'cgiquello' in group_names" - -- include: ../../../shared/account.yml user=cormoran uid=1219 - when: "'cormoran' in group_names" - -- include: ../../../shared/account.yml user=davidbgk uid=1251 - when: "'davidbgk' in group_names" - -- include: ../../../shared/account.yml user=don-vip uid=1247 - when: "'don-vip' in group_names" - -- include: ../../../shared/account.yml user=driss uid=1224 - when: "'driss' in group_names" - -- include: ../../../shared/account.yml user=etienne uid=1213 - when: "'etienne' in group_names" - -- include: ../../../shared/account.yml user=eloks uid=1214 - when: "'eloks' in group_names" - -- include: ../../../shared/account.yml user=famlam uid=1250 - when: "'famlam' in group_names" - -- include: ../../../shared/account.yml user=flacombe uid=1246 - when: "'flacombe' in group_names" - -- include: ../../../shared/account.yml user=francois2 uid=1221 - when: "'francois2' in group_names" - -- include: ../../../shared/account.yml user=fred uid=1205 - when: "'fred' in group_names" - -- include: ../../../shared/account.yml user=gileri uid=1311 - when: "'gileri' in group_names" - -- include: ../../../shared/account.yml user=guillaumeamat uid=1235 - when: "'guillaumeamat' in group_names" - -- include: ../../../shared/account.yml user=gpelloux uid=1237 - when: "'gpelloux' in group_names" - -- include: ../../../shared/account.yml user=hamlet uid=1305 - when: "'hamlet' in group_names" - -- include: ../../../shared/account.yml user=jacques uid=1306 - when: "'jacques' in group_names" - -- include: ../../../shared/account.yml user=jben uid=1206 - when: "'jben' in group_names" - -- include: ../../../shared/account.yml user=jgcailton uid=1207 - when: "'jgcailton' in group_names" - -- include: ../../../shared/account.yml user=juliep uid=1210 - when: "'juliep' in group_names" - -- include: ../../../shared/account.yml user=karl uid=1238 - when: "'karl' in group_names" - -- include: ../../../shared/account.yml user=lcombe uid=1215 - when: "'lcombe' in group_names" - -- include: ../../../shared/account.yml user=ljbouere uid=1248 - when: "'ljbouere' in group_names" - -- include: ../../../shared/account.yml user=mael uid=1218 - when: "'mael' in group_names" - -- include: ../../../shared/account.yml user=nlehuby uid=1220 - when: "'nlehuby' in group_names" - -- include: ../../../shared/account.yml user=nmoyroud uid=1226 - when: "'nmoyroud' in group_names" - -- include: ../../../shared/account.yml user=panieravide uid=1230 - when: "'panieravide' in group_names" - -- include: ../../../shared/account.yml user=phyks uid=1233 - when: "'phyks' in group_names" - -- include: ../../../shared/account.yml user=pyrog uid=1333 - when: "'pyrog' in group_names" - -- include: ../../../shared/account.yml user=redfox uid=1209 - when: "'redfox' in group_names" - -- include: ../../../shared/account.yml user=rodolphe uid=1208 - when: "'rodolphe' in group_names" - -- include: ../../../shared/account.yml user=rvoirin uid=1308 - when: "'rvoirin' in group_names" - -- include: ../../../shared/account.yml user=sly uid=1209 - when: "'sly' in group_names" - -- include: ../../../shared/account.yml user=stephanec uid=1225 - when: "'stephanec' in group_names" - -- include: ../../../shared/account.yml user=teslix uid=1222 - when: "'teslix' in group_names" - -- include: ../../../shared/account.yml user=thomasg77 uid=1249 - when: "'thomasg77' in group_names" - -- include: ../../../shared/account.yml user=thomasl uid=1210 - when: "'thomasl' in group_names" - -- include: ../../../shared/account.yml user=thorieux uid=1229 - when: "'thorieux' in group_names" - -- include: ../../../shared/account.yml user=thrrp uid=1310 - when: "'thrrp' in group_names" - -- include: ../../../shared/account.yml user=tykayn uid=1312 - when: "'tykayn' in group_names" - -- include: ../../../shared/account.yml user=tyndare uid=1212 - when: "'tyndare' in group_names" - -- include: ../../../shared/account.yml user=vdct uid=1217 - when: "'vdct' in group_names" - -- include: ../../../shared/account.yml user=ybon uid=1223 - when: "'ybon' in group_names" - -- include: ../../../shared/account.yml user=ydel uid=1313 - when: "'ydel' in group_names" +- name: Set accounts + include: ../../shared/account.yml user={{ item.user }} uid={{ item.uid }} + loop: "{{ users__accounts | dict2items(key_name = 'user') }}" + when: "item.user in group_names or (item.value.admin | default(false))" ... diff --git a/shared/account.yml b/shared/account.yml index 231b2cb3..05f9fa50 100644 --- a/shared/account.yml +++ b/shared/account.yml @@ -19,14 +19,18 @@ tags: user_creation - name: init ssh key to user {{ user }} - authorized_key: user={{ user }} key="{{ lookup('file',item) }}" + authorized_key: user={{ user }} key="{{ lookup('file',file) }}" tags: user_creation with_fileglob: - "{{ lookup('env','PWD') }}/public_keys/{{ user }}*" + loop_control: + loop_var: file - name: copy default config files - copy: force=no src="shared/files/default{{ item }}" dest="/home/{{ user }}/{{ item }}" owner={{ user }} group={{ user }} + copy: force=no src="shared/files/default{{ file }}" dest="/home/{{ user }}/{{ file }}" owner={{ user }} group={{ user }} tags: user_creation with_items: - .gitconfig - .vimrc + loop_control: + loop_var: file From c99afed5e0d706ac121bc9aa3f832b40401a5d78 Mon Sep 17 00:00:00 2001 From: Vincent Lafeychine Date: Sun, 8 Oct 2023 13:23:43 +0200 Subject: [PATCH 3/5] chore(role account): Rewrite to use builtins modules --- roles/users/files/default.gitconfig | 13 +++++++++ roles/users/files/default.vimrc | 16 +++++++++++ roles/users/tasks/account.yml | 41 +++++++++++++++++++++++++++++ roles/users/tasks/main.yml | 5 +++- shared/account.yml | 36 ------------------------- 5 files changed, 74 insertions(+), 37 deletions(-) create mode 100644 roles/users/files/default.gitconfig create mode 100644 roles/users/files/default.vimrc create mode 100644 roles/users/tasks/account.yml delete mode 100644 shared/account.yml diff --git a/roles/users/files/default.gitconfig b/roles/users/files/default.gitconfig new file mode 100644 index 00000000..98421525 --- /dev/null +++ b/roles/users/files/default.gitconfig @@ -0,0 +1,13 @@ +[color] + diff = auto + status = auto + branch = auto +[alias] + st = status + ci = commit + br = branch + cp = cherry-pick + logf = log --follow +[log] + decorate = short + diff --git a/roles/users/files/default.vimrc b/roles/users/files/default.vimrc new file mode 100644 index 00000000..ac3ac296 --- /dev/null +++ b/roles/users/files/default.vimrc @@ -0,0 +1,16 @@ +colorscheme elflord +syn on +set ruler +set noai +set title + +set is " incremental search +set hlsearch + +set foldlevel=500 + +" Pour se souvenir de la dernière position dans le fichier +autocmd BufReadPost * + \ if line("'\"") > 0 && line("'\"") <= line("$") | + \ exe "normal g`\"" | + \ endif diff --git a/roles/users/tasks/account.yml b/roles/users/tasks/account.yml new file mode 100644 index 00000000..a9377d5a --- /dev/null +++ b/roles/users/tasks/account.yml @@ -0,0 +1,41 @@ +--- +- name: Set {{ user }} group + group: + name: "{{ user }}" + +- name: Set {{ user }} account + user: + group: "{{ user }}" + home: "/home/{{ user }}" + name: "{{ user }}" + uid: "{{ uid }}" + +- name: Initialise /data/work/ folder for {{ user }} + file: + path: /data/work/{{ user }} + state: directory + group: "{{ user }}" + owner: "{{ user }}" + +- name: Copy SSH key of user {{ user }} + authorized_key: + user: "{{ user }}" + key: "{{ lookup('file', file) }}" + with_fileglob: + - "public_keys/{{ user }}*" + loop_control: + loop_var: file + +- name: Copy default config files + copy: + force: false + src: "default{{ file }}" + dest: "/home/{{ user }}/{{ file }}" + group: "{{ user }}" + owner: "{{ user }}" + loop: + - .gitconfig + - .vimrc + loop_control: + loop_var: file +... diff --git a/roles/users/tasks/main.yml b/roles/users/tasks/main.yml index 35c4096a..2aedb82f 100644 --- a/roles/users/tasks/main.yml +++ b/roles/users/tasks/main.yml @@ -1,6 +1,9 @@ --- - name: Set accounts - include: ../../shared/account.yml user={{ item.user }} uid={{ item.uid }} + include_tasks: account.yml + vars: + user: "{{ item.user }}" + uid: "{{ item.value.uid }}" loop: "{{ users__accounts | dict2items(key_name = 'user') }}" when: "item.user in group_names or (item.value.admin | default(false))" ... diff --git a/shared/account.yml b/shared/account.yml deleted file mode 100644 index 05f9fa50..00000000 --- a/shared/account.yml +++ /dev/null @@ -1,36 +0,0 @@ -- name: Check if user {{ user }} exists - action: shell /usr/bin/getent passwd {{ user }} - register: user_exist - ignore_errors: True - changed_when: "user_exist.rc != 0" - tags: user_creation - -- name: init user {{ user }} - user: name={{ user }} home=/home/{{ user }}/ shell=/bin/bash uid={{ uid }} - when: user_exist.changed - tags: user_creation - -- name: init group {{ user }} - group: name={{ user }} - tags: user_creation - -- name: init /data/work/ path for {{ user }} - file: path=/data/work/{{ user }} state=directory owner={{ user }} group={{ user }} - tags: user_creation - -- name: init ssh key to user {{ user }} - authorized_key: user={{ user }} key="{{ lookup('file',file) }}" - tags: user_creation - with_fileglob: - - "{{ lookup('env','PWD') }}/public_keys/{{ user }}*" - loop_control: - loop_var: file - -- name: copy default config files - copy: force=no src="shared/files/default{{ file }}" dest="/home/{{ user }}/{{ file }}" owner={{ user }} group={{ user }} - tags: user_creation - with_items: - - .gitconfig - - .vimrc - loop_control: - loop_var: file From 3d27fb1754c21deac484b79b5164c455c1a9c855 Mon Sep 17 00:00:00 2001 From: Vincent Lafeychine Date: Sun, 8 Oct 2023 13:24:27 +0200 Subject: [PATCH 4/5] feat: Add accounts playbook to only handle users accounts --- accounts.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 accounts.yml diff --git a/accounts.yml b/accounts.yml new file mode 100644 index 00000000..bb0aa6fb --- /dev/null +++ b/accounts.yml @@ -0,0 +1,6 @@ +- name: default configuration + hosts: all + gather_facts: no + become: yes + roles: + - users From 2bb25e198f2acdcd8b358142f5599ddac9a942ec Mon Sep 17 00:00:00 2001 From: Vincent Lafeychine Date: Thu, 12 Oct 2023 23:17:58 +0200 Subject: [PATCH 5/5] chore: Rename role 'users' into 'accounts' --- accounts.yml | 2 +- common.yml | 2 +- group_vars/all/{users.yml => accounts.yml} | 2 +- roles/accounts/defaults/main.yml | 3 +++ roles/{users => accounts}/files/default.gitconfig | 0 roles/{users => accounts}/files/default.vimrc | 0 roles/{users => accounts}/tasks/account.yml | 2 +- roles/{users => accounts}/tasks/main.yml | 2 +- roles/users/defaults/main.yml | 3 --- 9 files changed, 8 insertions(+), 8 deletions(-) rename group_vars/all/{users.yml => accounts.yml} (98%) create mode 100644 roles/accounts/defaults/main.yml rename roles/{users => accounts}/files/default.gitconfig (100%) rename roles/{users => accounts}/files/default.vimrc (100%) rename roles/{users => accounts}/tasks/account.yml (96%) rename roles/{users => accounts}/tasks/main.yml (75%) delete mode 100644 roles/users/defaults/main.yml diff --git a/accounts.yml b/accounts.yml index bb0aa6fb..46a1f996 100644 --- a/accounts.yml +++ b/accounts.yml @@ -3,4 +3,4 @@ gather_facts: no become: yes roles: - - users + - accounts diff --git a/common.yml b/common.yml index 44fb5027..ab4bae7a 100644 --- a/common.yml +++ b/common.yml @@ -4,4 +4,4 @@ become: yes roles: - common - - users + - accounts diff --git a/group_vars/all/users.yml b/group_vars/all/accounts.yml similarity index 98% rename from group_vars/all/users.yml rename to group_vars/all/accounts.yml index 5c8c1f92..bd802ed8 100644 --- a/group_vars/all/users.yml +++ b/group_vars/all/accounts.yml @@ -1,5 +1,5 @@ --- -users__accounts: +accounts__users: cquest: uid: 1202 admin: true diff --git a/roles/accounts/defaults/main.yml b/roles/accounts/defaults/main.yml new file mode 100644 index 00000000..c61f82ee --- /dev/null +++ b/roles/accounts/defaults/main.yml @@ -0,0 +1,3 @@ +--- +accounts__users: {} +... diff --git a/roles/users/files/default.gitconfig b/roles/accounts/files/default.gitconfig similarity index 100% rename from roles/users/files/default.gitconfig rename to roles/accounts/files/default.gitconfig diff --git a/roles/users/files/default.vimrc b/roles/accounts/files/default.vimrc similarity index 100% rename from roles/users/files/default.vimrc rename to roles/accounts/files/default.vimrc diff --git a/roles/users/tasks/account.yml b/roles/accounts/tasks/account.yml similarity index 96% rename from roles/users/tasks/account.yml rename to roles/accounts/tasks/account.yml index a9377d5a..a921ee8f 100644 --- a/roles/users/tasks/account.yml +++ b/roles/accounts/tasks/account.yml @@ -6,7 +6,7 @@ - name: Set {{ user }} account user: group: "{{ user }}" - home: "/home/{{ user }}" + home: "/home/{{ user }}/" name: "{{ user }}" uid: "{{ uid }}" diff --git a/roles/users/tasks/main.yml b/roles/accounts/tasks/main.yml similarity index 75% rename from roles/users/tasks/main.yml rename to roles/accounts/tasks/main.yml index 2aedb82f..1d3db707 100644 --- a/roles/users/tasks/main.yml +++ b/roles/accounts/tasks/main.yml @@ -4,6 +4,6 @@ vars: user: "{{ item.user }}" uid: "{{ item.value.uid }}" - loop: "{{ users__accounts | dict2items(key_name = 'user') }}" + loop: "{{ accounts__users | dict2items(key_name = 'user') }}" when: "item.user in group_names or (item.value.admin | default(false))" ... diff --git a/roles/users/defaults/main.yml b/roles/users/defaults/main.yml deleted file mode 100644 index 38b5cc02..00000000 --- a/roles/users/defaults/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -users__accounts: {} -...