|
1 | 1 | ---
|
| 2 | + |
2 | 3 | - name: Generate identity-management inventory based off of engagement.json
|
3 | 4 | hosts: local
|
4 | 5 | gather_facts: true
|
|
13 | 14 | include_vars:
|
14 | 15 | file: "{{ directory }}/engagement.json"
|
15 | 16 |
|
| 17 | + - name: Check if Runtime Data file exist |
| 18 | + stat: |
| 19 | + path: "{{ directory }}/runtime.json" |
| 20 | + register: runtime_file_data |
| 21 | + |
| 22 | + - name: Fail if runtime.json not found |
| 23 | + fail: |
| 24 | + msg: "The runtime.json file not found" |
| 25 | + when: not runtime_file_data.stat.exists |
| 26 | + |
| 27 | + - name: Read Runtime Data |
| 28 | + include_vars: |
| 29 | + file: "{{ directory }}/runtime.json" |
| 30 | + when: runtime_file_data.stat.exists |
| 31 | + |
16 | 32 | - name: "Fail If Governor Type Is Not Provided"
|
17 | 33 | fail:
|
18 | 34 | msg: "governor_type and governor_spec vars need to be provided in order to indicate babylon workflow"
|
19 | 35 | when:
|
20 | 36 | - (governor_type is undefined or (governor_type | trim) == "") or (governor_spec is undefined or (governor_spec | trim) == "")
|
21 | 37 |
|
| 38 | + - name: "Fail if user_options.user_roles.options Is Not Provided" |
| 39 | + fail: |
| 40 | + msg: "user_options.user_roles.options is not defined at runtime.json file or contain incorrect values" |
| 41 | + when: > |
| 42 | + user_options is undefined or |
| 43 | + user_options.user_roles is undefined or |
| 44 | + user_options.user_roles.options is undefined or |
| 45 | + user_options.user_roles.options[0].value is undefined |
| 46 | +
|
22 | 47 | - name: Generate Timestamp
|
23 | 48 | set_fact:
|
24 | 49 | inv_ts: "{{ lookup('pipe','date +%Y%m%d%H%M%S') }}"
|
|
30 | 55 | - "ocp-admin-credentials.json"
|
31 | 56 | - "ocp-ldap-sa-credentials.json"
|
32 | 57 |
|
33 |
| - - name: "Add users to inventory" |
34 |
| - set_fact: |
35 |
| - users: "{{ (users | default([])) + [ { 'first_name': (item.first_name | trim), 'last_name': (item.last_name | trim), 'email': (item.email | trim) , 'user_name': (item.email.split('@')[0] | trim) } ] }}" |
36 |
| - loop: "{{ engagement_users }}" |
| 58 | + ##################################################################################################################### |
| 59 | + # Process list of users in the queue that needs to be removed |
| 60 | + # |
| 61 | + - block: |
| 62 | + - include_tasks: process_queue_list.yml |
| 63 | + - include_tasks: process_list_of_users.yml |
| 64 | + vars: |
| 65 | + list_of_users_to_process: "{{ list_of_users_to_remove | d([]) }}" |
| 66 | + - set_fact: |
| 67 | + users_to_remove: "{{ processed_users | d([]) }}" |
37 | 68 |
|
38 |
| - - name: "Add LDAP Service Account" |
39 |
| - set_fact: |
40 |
| - users: "{{ (users | default([])) + [ { 'first_name': 'LDAP', 'last_name': 'SA', 'email': '[email protected]', 'user_name': ocp_ldap_sa_username, 'generate_password': False, 'notify_user': False, 'password': ocp_ldap_sa_password } ] }}" |
| 69 | + ##################################################################################################################### |
| 70 | + # Process list of users that are part of this engagement |
| 71 | + # |
| 72 | + - block: |
| 73 | + - include_tasks: process_list_of_users.yml |
| 74 | + vars: |
| 75 | + list_of_users_to_process: "{{ engagement_users | d([]) }}" |
| 76 | + - set_fact: |
| 77 | + users: "{{ processed_users | d([]) }}" |
41 | 78 |
|
42 |
| - - name: "Get Unique Groups" |
| 79 | + ##################################################################################################################### |
| 80 | + # Process user groups and group memberships |
| 81 | + # |
| 82 | + - include_tasks: process_groups.yml |
| 83 | + loop_control: |
| 84 | + loop_var: group_item |
| 85 | + loop: "{{ user_options.user_roles.options }}" |
| 86 | + |
| 87 | + - name: "Get Unique Groups from runtime config" |
43 | 88 | set_fact:
|
44 |
| - unique_groups: "{{ engagement_users | json_query('[].role') | unique }}" |
| 89 | + unique_groups: "{{ user_options.user_roles.options | json_query('[].value') | unique }}" |
45 | 90 |
|
46 |
| - - name: "Set Group Membership" |
| 91 | + ##################################################################################################################### |
| 92 | + # Add in the LDAP SA and group sync memberships |
| 93 | + # |
| 94 | + - name: "Create a LDAP user and group facts to simplify processing below" |
| 95 | + set_fact: |
| 96 | + ldap_users: |
| 97 | + - first_name: 'LDAP' |
| 98 | + last_name: 'SA' |
| 99 | + |
| 100 | + user_name: "{{ ocp_ldap_sa_username }}" |
| 101 | + password: "{{ ocp_ldap_sa_password }}" |
| 102 | + generate_password: False |
| 103 | + notify_user: False |
| 104 | + ldap_groups: |
| 105 | + - name: 'ldap-members' |
| 106 | + childgroups: "{{ unique_groups }}" |
| 107 | + |
| 108 | + - name: "Add LDAP Service Account to list of users" |
47 | 109 | set_fact:
|
48 |
| - usrgrp: "{{ (usrgrp | default([])) + [ {'name': item, 'members': (engagement_users | selectattr('role','equalto',item) | map(attribute='email') | map('regex_replace','@.*','') | list) } ] }}" |
49 |
| - loop: "{{ unique_groups }}" |
| 110 | + users: "{{ (users | default([])) + ldap_users }}" |
50 | 111 |
|
51 | 112 | - name: Add LDAP Groups Grouping
|
52 | 113 | set_fact:
|
53 |
| - usrgrp: "{{ (usrgrp | default([])) + [ {'name': 'ldap-members', 'childgroups': unique_groups } ] }}" |
| 114 | + user_groups: "{{ (user_groups | default([])) + ldap_groups }}" |
| 115 | + |
54 | 116 |
|
| 117 | + ##################################################################################################################### |
| 118 | + # Generate the CC list for emails |
| 119 | + # |
55 | 120 | - name: "Set List of Mail CC"
|
56 | 121 | set_fact:
|
57 | 122 | cc_list: "{{ ', '.join(( '{{ engagement_lead_email }}', '{{ technical_lead_email }}' )) }}"
|
58 | 123 |
|
59 |
| - - name: "Check for Job queue" |
60 |
| - ansible.builtin.stat: |
61 |
| - path: "{{ directory }}/queue" |
62 |
| - register: job_queue |
63 |
| - ignore_errors: True |
64 |
| - |
65 |
| - - name: "Process Job queue" |
66 |
| - include: "queue/main.yml" |
67 |
| - when: |
68 |
| - - job_queue.stat.isdir is defined |
69 | 124 |
|
| 125 | + ##################################################################################################################### |
| 126 | + # Gather repository facts for better processing below |
| 127 | + # |
70 | 128 | - name: "Set repository information"
|
71 | 129 | set_fact:
|
72 | 130 | repository_url: "{{ url | default(omit) }}"
|
73 | 131 | repository_ssh_key: "{{ lookup('file', ssh_key_data_path, lstrip=False, rstrip=False) | default(omit) }}"
|
74 | 132 | repository_username: "{{ username if username is defined else omit }}"
|
75 | 133 | repository_password: "{{ password if password is defined else omit }}"
|
76 | 134 |
|
| 135 | + |
77 | 136 | #####################################################################################################################
|
78 | 137 | # Right now, the only supported configuration is a list of one hosting environment.
|
79 | 138 | # In the near future, this should be updated to support more than one, and this comment (and the code below)
|
|
103 | 162 | list_of_mail_cc: "{{ cc_list }}"
|
104 | 163 | lodestar_identities:
|
105 | 164 | users: "{{ users }}"
|
106 |
| - groups: "{{ usrgrp }}" |
| 165 | + groups: "{{ user_groups }}" |
107 | 166 | lodestar_identities_remove:
|
108 |
| - users: "{{ users_remove | default([]) }}" |
| 167 | + users: "{{ users_to_remove | default([]) }}" |
109 | 168 | repository:
|
110 | 169 | url: "{{ repository_url if repository_url is defined else omit }}"
|
111 | 170 | ssh_key: "{{ ( repository_ssh_key | to_nice_yaml( default_style='>-', indent=4, width=5000 ) | trim) if repository_ssh_key is defined else omit }}"
|
|
0 commit comments