From df3e562c68ec51aaae242ad5f792bc83d67a0bde Mon Sep 17 00:00:00 2001 From: Jakub Filipczak Date: Wed, 10 Aug 2022 13:15:48 +0200 Subject: [PATCH 1/4] inventory-generation/identity-management/main.yml --- .../identity-management/main.yml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/inventory-generation/identity-management/main.yml b/inventory-generation/identity-management/main.yml index 1d1b1e9..ca5390d 100644 --- a/inventory-generation/identity-management/main.yml +++ b/inventory-generation/identity-management/main.yml @@ -66,6 +66,13 @@ - set_fact: users_to_remove: "{{ processed_users | d([]) }}" + ##################################################################################################################### + # Create generic users + # + + - block: + - include: create_generic_users + ##################################################################################################################### # Process list of users that are part of this engagement # @@ -114,6 +121,23 @@ user_groups: "{{ (user_groups | default([])) + ldap_groups }}" + - name: Create generic accounts + set_fact: + generic_accounts: + - first_name: 'lab%02x' + last_name: 'lab%02x' + email: 'lab%02x@localhost.com' + user_name: "lab%02x" + password: "lab%02x" + generate_password: False + notify_user: False + with_sequence: start=0 end={{ number_of_generic_accounts | default(5) }} format=lab%02x + + - name: Add generic accounts to the user list + set_fact: + users: "{{ (users | default([])) + generic_accounts }}" + + ##################################################################################################################### # Generate the CC list for emails # From 0ebd5f2fb1319f1fb0f1a88f91e1fd7937cc8f63 Mon Sep 17 00:00:00 2001 From: Jakub Filipczak Date: Wed, 10 Aug 2022 14:13:33 +0200 Subject: [PATCH 2/4] Remove some leftovers --- inventory-generation/identity-management/main.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/inventory-generation/identity-management/main.yml b/inventory-generation/identity-management/main.yml index ca5390d..db6aab0 100644 --- a/inventory-generation/identity-management/main.yml +++ b/inventory-generation/identity-management/main.yml @@ -66,13 +66,6 @@ - set_fact: users_to_remove: "{{ processed_users | d([]) }}" - ##################################################################################################################### - # Create generic users - # - - - block: - - include: create_generic_users - ##################################################################################################################### # Process list of users that are part of this engagement # @@ -122,7 +115,7 @@ - name: Create generic accounts - set_fact: + set_fact: generic_accounts: - first_name: 'lab%02x' last_name: 'lab%02x' @@ -134,7 +127,7 @@ with_sequence: start=0 end={{ number_of_generic_accounts | default(5) }} format=lab%02x - name: Add generic accounts to the user list - set_fact: + set_fact: users: "{{ (users | default([])) + generic_accounts }}" From c5724aaf93dc75e472c300af7caa5683edd9be70 Mon Sep 17 00:00:00 2001 From: Jakub Filipczak Date: Wed, 10 Aug 2022 17:20:12 +0200 Subject: [PATCH 3/4] another approach on creating generic accounts --- .../create_generic_accounts.yml | 18 ++++++++++++++++++ .../identity-management/main.yml | 17 ++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 inventory-generation/identity-management/create_generic_accounts.yml diff --git a/inventory-generation/identity-management/create_generic_accounts.yml b/inventory-generation/identity-management/create_generic_accounts.yml new file mode 100644 index 0000000..e63eeea --- /dev/null +++ b/inventory-generation/identity-management/create_generic_accounts.yml @@ -0,0 +1,18 @@ +--- +- set_fact: + generic_accounts: [] +- name: Create generic accounts + set_fact: + generic_account: + - first_name: 'lab{{ item }}' + last_name: 'lab{{ item }}' + email: 'lab{{ item }}@localhost.com' + user_name: "lab{{ item }}" + password: "lab{{ item }}" + generate_password: False + notify_user: False + +- name: Add generic accounts to the user list + set_fact: + generic_accounts: "{{ generic_accounts + generic_account }}" + diff --git a/inventory-generation/identity-management/main.yml b/inventory-generation/identity-management/main.yml index db6aab0..ae051d4 100644 --- a/inventory-generation/identity-management/main.yml +++ b/inventory-generation/identity-management/main.yml @@ -39,7 +39,7 @@ fail: msg: "user_options.user_roles.options is not defined at runtime.json file or contain incorrect values" when: > - user_options is undefined or + user_options is undefined or user_options.user_roles is undefined or user_options.user_roles.options is undefined or user_options.user_roles.options[0].value is undefined @@ -113,19 +113,10 @@ set_fact: user_groups: "{{ (user_groups | default([])) + ldap_groups }}" - - name: Create generic accounts - set_fact: - generic_accounts: - - first_name: 'lab%02x' - last_name: 'lab%02x' - email: 'lab%02x@localhost.com' - user_name: "lab%02x" - password: "lab%02x" - generate_password: False - notify_user: False - with_sequence: start=0 end={{ number_of_generic_accounts | default(5) }} format=lab%02x - + include_tasks: create_generic_accounts.yml + loop: "{{ range(0,5,1)|list }}" +## how to inject variable as a range filter param? - name: Add generic accounts to the user list set_fact: users: "{{ (users | default([])) + generic_accounts }}" From 9e4ac6a3328958c18c44dcfd8cc7b87264db7658 Mon Sep 17 00:00:00 2001 From: Jakub Filipczak Date: Thu, 11 Aug 2022 15:40:45 +0200 Subject: [PATCH 4/4] update handling of generic accounts --- .../create_generic_accounts.yml | 18 ----------- .../identity-management/main.yml | 31 +++++++++++++++++-- 2 files changed, 28 insertions(+), 21 deletions(-) delete mode 100644 inventory-generation/identity-management/create_generic_accounts.yml diff --git a/inventory-generation/identity-management/create_generic_accounts.yml b/inventory-generation/identity-management/create_generic_accounts.yml deleted file mode 100644 index e63eeea..0000000 --- a/inventory-generation/identity-management/create_generic_accounts.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- set_fact: - generic_accounts: [] -- name: Create generic accounts - set_fact: - generic_account: - - first_name: 'lab{{ item }}' - last_name: 'lab{{ item }}' - email: 'lab{{ item }}@localhost.com' - user_name: "lab{{ item }}" - password: "lab{{ item }}" - generate_password: False - notify_user: False - -- name: Add generic accounts to the user list - set_fact: - generic_accounts: "{{ generic_accounts + generic_account }}" - diff --git a/inventory-generation/identity-management/main.yml b/inventory-generation/identity-management/main.yml index ae051d4..1c4b4c3 100644 --- a/inventory-generation/identity-management/main.yml +++ b/inventory-generation/identity-management/main.yml @@ -113,13 +113,38 @@ set_fact: user_groups: "{{ (user_groups | default([])) + ldap_groups }}" + + ##################################################################################################################### + # Create generic user accounts + # + - name: Create generic accounts - include_tasks: create_generic_accounts.yml - loop: "{{ range(0,5,1)|list }}" -## how to inject variable as a range filter param? + set_fact: + generic_accounts: >- + {{ generic_accounts|d([]) + + [{ + 'first_name': 'lab' + item|string, + 'last_name': 'lab' + item|string, + 'email': 'lab' + item|string + '@localhost.com', + 'user_name': 'lab' + item|string, + 'password': 'lab' + item|string, + 'generate_password': False, + 'notify_user': False + }] + }} + user_names: "{{ user_names|d([]) + [ generic_accounts_base_name|d('lab')|string + item|string ] }}" + loop: "{{ range(1, number_of_generic_accounts+1)|list }}" + + - set_fact: + generic_accounts_group: "{{ [{'name': generic_accounts_group_name|d('student')|string, 'members': user_names}] }}" + + - debug: + var: group_members + - name: Add generic accounts to the user list set_fact: users: "{{ (users | default([])) + generic_accounts }}" + user_groups: "{{ (user_groups | default([])) + generic_accounts_group }}" #####################################################################################################################