From abd0943645fa2752ad87b440a8a4beb4b4f51d17 Mon Sep 17 00:00:00 2001 From: Jean-Marie Mineau Date: Fri, 29 Jan 2021 23:49:19 +0100 Subject: [PATCH] generate users --- group_vars/all/user_vault | 56 +++++++++++++++++++++++++++---- roles/create_users/tasks/main.yml | 41 +++++++++++++++------- 2 files changed, 78 insertions(+), 19 deletions(-) diff --git a/group_vars/all/user_vault b/group_vars/all/user_vault index 53181a6..83e9db5 100644 --- a/group_vars/all/user_vault +++ b/group_vars/all/user_vault @@ -1,8 +1,50 @@ $ANSIBLE_VAULT;1.2;AES256;user_vault -37313030326130633030646433616330333664343237343231353463376434343938353766356464 -3731313633666539353130376139306663653336356363640a643465666563366635343763643931 -61383664353531643035333033623865396562613562353438666264343334613461626130386566 -3637656132353236660a366562633064333034633464343661663538353263643237313735366435 -38393639326233333938636636396363666536366139623666653434316537326430333333376638 -37663734653162633462653864353663323564623639313639326435313939336162643935383831 -303931333131396565393336653732626134 +39613161656536323036396563343336633736613437303437386634363566333363356566633839 +3933343464366531376239366264386130366265613831620a646534303735393237336465643838 +35646438643030323834363233326639313365626631363335623433346538373833356630333133 +6238343231613931330a366561636234623233663061613032376166386166323465653030666435 +38396465666630663935313136356232633165326439656364303465633134313866356466616165 +62333962653537303436323463383137383039303734616333613830383639353563303463373739 +64353138626263376535396461306339393364363662323737323138663934306562616232623263 +39343736313134356432643734353336626562353234653738376166663333333963643236373630 +63656362363437653432656234376139343330373461356264626534386664643234363136326561 +36666638646132326136646664303435316661316366333234373564656463326564653230353835 +37383235626464343462343037643664656535333836636262313762363365333565636666313361 +34613533366366623637623836363437656137656637613433623863363436383930646234306433 +63363736663038366135366439373437346461613661366634366665316436666338306638336537 +61333836653538303633386331333539653234386235353739616136303331646535656336646264 +62376535326537323865643966393663623065343138663264356234343961613935623561663966 +30396430663130393861336363633138633731623937643232393837393636626264376332333539 +37613036323333353539646162383336636339376165363135316430393264653463386664383664 +33646666636631613434316134353838636366346463353234346534346463653331613961343134 +61366539343535386238666462623463386333663636393930336337396638626132636531623961 +34663430663364656438306235366636333232356563313533336339623461636466643335346633 +61313962313762633563393965663666333032363666613539666534613032376535323636393761 +64343664343964373839346164623438323364336433353132313061633063663837373730303762 +34633530356137663837383231323162383930393962656232313733343539653164303436313365 +34613464383939323033656264306139663839363461626661656339663036353434333635623531 +62303366376664313264663836343037616463616134353561303263666366353431626436666465 +36346563623536396232323666333636353066323338393565633262656161333139663063303064 +38343032336661313237623066646265356335373039643562653661666438326635353165313239 +34323361363737643534383465343265323664633866613963623762396239306361353562333266 +39636438306638646134303431363137306164613935663430323431336435626534393065356335 +32386130383031353236373838613466633136333739646237633863393930306665366461363262 +35616364343039396662373164333632386466643665316238633235616531396666363661646437 +39353533653836343763616162346134323262363035356631353832343532633362313137616464 +64356636313365666565363561313238303630666130613833303435636336366237613065316262 +39626632346661656361646330353830313336653833333533393038346162613032346239346466 +66643036643364313438633364323634613666313934663633383134393332656135623338326337 +66653561373166336365373637613930396165343039376239633461303863323662363134386130 +66613934343061373864346333383265343666313232336363623834336439326563616366633136 +61646165356536636564643664653262373039313664393631373637316366346331666132613737 +35303838356639626264656236383738323635326235366530316133376336326535303661393838 +33346238333239663937336661623239613764623130333339343039633462663434666133396166 +36366233393062643565653138303838646462306364366163613736663830396564663863316164 +34366666386531323034383638363334653937656262316566663264663132353332383666643332 +30613031653162386134306564303565666464336139373837656635643236353737316434633930 +38616130633665646434373431386337333062636164666235616430353364316263663036356539 +35393564316134646663363530366139353365363062343562383037386530343862653536616566 +37313064613561646462613666323134653761336234396566643261623334643639626333616233 +65623232303238316163623261653736656234656531363030363962623235306437303866643837 +61326565396533643165376263353232326537386530616137323661313066643732303161336638 +35303032316366376236363964393339386461353735313534623162656234363335 diff --git a/roles/create_users/tasks/main.yml b/roles/create_users/tasks/main.yml index 33c40d2..942c434 100644 --- a/roles/create_users/tasks/main.yml +++ b/roles/create_users/tasks/main.yml @@ -1,16 +1,33 @@ --- -#- name: Generate user -# user: -# name: "{{ item.name }}" -# group: "{{ item.groups }}" -# loop: "{{ uservault_users }}" -# -- name: Test - debug: - msg: "{{ item.name }}" +- name: Generate user + user: + name: "{{ item.name }}" + groups: "{{ item.groups }}" + loop: "{{ uservault_users }}" + +- name: Set the passwords + replace: + path: /etc/shadow + regexp: '^{{ item.name }}:(.*?):(.*)' + replace: '{{ item.name }}:{{ item.password_hash }}:\2' + loop: "{{ uservault_users }}" + +- name: Create .ssh file + file: + path: "/home/{{ item.name }}/.ssh" + state: directory + owner: "{{ item.name }}" + group: "{{ item.name }}" + loop: "{{ uservault_users }}" + +- name: Add the key to the authorized_keys + lineinfile: + path: "/home/{{ item.name }}/.ssh/authorized_keys" + create: yes + mode: '0600' + owner: "{{ item.name }}" + group: "{{ item.name }}" + line: "{{ item.ssh_key }}" loop: "{{ uservault_users }}" -- name: Test name - debug: - msg: "{{ vault_email }}"