Skip to content

Commit

Permalink
Merge pull request #415 from automationiberia/filetree-read-active-pa…
Browse files Browse the repository at this point in the history
…ssive-site

[filetree_read role] - Added controller_location variable to handle multiple sites and loop…
  • Loading branch information
ivarmu authored Nov 21, 2022
2 parents 0c8da80 + 0b5b1a8 commit 5b3eb8c
Show file tree
Hide file tree
Showing 22 changed files with 328 additions and 69 deletions.
1 change: 1 addition & 0 deletions roles/filetree_read/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The following Variables set the organization where should be applied the configu
|`orgs:`|Acme|yes|This variable sets the organization where should be applied the configuration.|
|`dir_orgs_vars:`|orgs_vars|yes|This variable sets the directory path where the variables will be store.|
|`env:`|dev|yes|This variable sets the life-cycle environment to use.|
|`controller_location:`|''|no|This variable sets object localtion. It is useful when the configuration need to be replicated in an active/passive sites architecture|
|`filetree_controller_settings`|{{ dir_orgs_vars }}/{{ orgs }}/env/{{ env }}/controller_settings.d/|yes|Directory path to load controller object variables|
|`filetree_controller_organizations`|{{ dir_orgs_vars }}/{{ orgs }}/env/common/controller_organizations.d/|yes|Directory path to load controller object variables|
|`filetree_controller_labels`|{{ dir_orgs_vars }}/{{ orgs }}/env/common/controller_labels.d/|yes|Directory path to load controller object variables|
Expand Down
10 changes: 7 additions & 3 deletions roles/filetree_read/tasks/applications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

- name: "Read Applications definitions"
ansible.builtin.include_vars:
file: "{{ item.path }}"
file: "{{ __read_applications_definitions_item.path }}"
loop: "{{ __list_files_controller_applications.files }}"
loop_control:
loop_var: __read_applications_definitions_item
register: __contents_filetree_controller_applications

- name: "Populate Applications list"
ansible.builtin.set_fact:
__populate_controller_applications: "{{ (__populate_controller_applications | default([])) + item.ansible_facts.controller_applications }}"
__populate_controller_applications: "{{ (__populate_controller_applications | default([])) + __populate_applications_list_item.ansible_facts.controller_applications }}"
loop: "{{ __contents_filetree_controller_applications.results }}"
when: __contents_filetree_controller_applications.results is defined and item.ansible_facts.controller_applications is defined
loop_control:
loop_var: __populate_applications_list_item
when: __contents_filetree_controller_applications.results is defined and __populate_applications_list_item.ansible_facts.controller_applications is defined

- name: "Set Applications Data Structure"
ansible.builtin.set_fact:
Expand Down
10 changes: 7 additions & 3 deletions roles/filetree_read/tasks/credential_input_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

- name: "Read Credential Input Sources definitions"
ansible.builtin.include_vars:
file: "{{ item.path }}"
file: "{{ __read_input_sources_definitions_item.path }}"
loop: "{{ __list_files_controller_credential_input_sources.files }}"
loop_control:
loop_var: __read_input_sources_definitions_item
register: __contents_filetree_controller_credential_input_sources

- name: "Populate Credential Input Sources list"
ansible.builtin.set_fact:
__populate_controller_credential_input_sources: "{{ (__populate_controller_credential_input_sources | default([])) + item.ansible_facts.controller_credential_input_sources }}"
__populate_controller_credential_input_sources: "{{ (__populate_controller_credential_input_sources | default([])) + __populate_input_sources_list_item.ansible_facts.controller_credential_input_sources }}"
loop: "{{ __contents_filetree_controller_credential_input_sources.results }}"
when: __contents_filetree_controller_credential_input_sources.results is defined and item.ansible_facts.controller_credential_input_sources is defined
loop_control:
loop_var: __populate_input_sources_list_item
when: __contents_filetree_controller_credential_input_sources.results is defined and __populate_input_sources_list_item.ansible_facts.controller_credential_input_sources is defined

- name: "Set Credential Input Sources Data Structure"
ansible.builtin.set_fact:
Expand Down
10 changes: 7 additions & 3 deletions roles/filetree_read/tasks/credential_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

- name: "Read Credential_Types definitions"
ansible.builtin.include_vars:
file: "{{ item.path }}"
file: "{{ __read_credentials_definitions_item.path }}"
loop: "{{ __list_files_controller_credential_types.files }}"
loop_control:
loop_var: __read_credentials_definitions_item
register: __contents_filetree_controller_credential_types

- name: "Populate Credential_Types list"
ansible.builtin.set_fact:
__populate_controller_credential_types: "{{ (__populate_controller_credential_types | default([])) + item.ansible_facts.controller_credential_types }}"
__populate_controller_credential_types: "{{ (__populate_controller_credential_types | default([])) + __populate_credentials_list_item.ansible_facts.controller_credential_types }}"
loop: "{{ __contents_filetree_controller_credential_types.results }}"
when: __contents_filetree_controller_credential_types.results is defined and item.ansible_facts.controller_credential_types is defined
loop_control:
loop_var: __populate_credentials_list_item
when: __contents_filetree_controller_credential_types.results is defined and __populate_credentials_list_item.ansible_facts.controller_credential_types is defined

- name: "Set Projects Data Structure"
ansible.builtin.set_fact:
Expand Down
39 changes: 36 additions & 3 deletions roles/filetree_read/tasks/credentials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,48 @@

- name: "Read Credentials definitions"
ansible.builtin.include_vars:
file: "{{ item.path }}"
file: "{{ __read_credentials_definitions_item.path }}"
loop: "{{ __list_files_controller_credentials.files }}"
loop_control:
loop_var: __read_credentials_definitions_item
register: __contents_filetree_controller_credentials

- name: "Populate Credentials list"
ansible.builtin.set_fact:
__populate_controller_credentials: "{{ (__populate_controller_credentials | default([])) + item.ansible_facts.controller_credentials }}"
__populate_controller_credentials: "{{ (__populate_controller_credentials | default([])) + __populate_credentials_list_item.ansible_facts.controller_credentials }}"
loop: "{{ __contents_filetree_controller_credentials.results }}"
when: __contents_filetree_controller_credentials.results is defined and item.ansible_facts.controller_credentials is defined
loop_control:
loop_var: __populate_credentials_list_item
when: __contents_filetree_controller_credentials.results is defined and __populate_credentials_list_item.ansible_facts.controller_credentials is defined

- name: "Segregated Credentials list when controller_location is defined"
when: controller_location is defined and __populate_controller_credentials is defined
block:
- name: "Populate Credentials list by _common objects"
ansible.builtin.set_fact:
__populate_controller_credentials_common: "{{ (__populate_controller_credentials_common | default([])) + [__populate_credentials_list_common_item] }}"
loop: "{{ __populate_controller_credentials }}"
loop_control:
loop_var: __populate_credentials_list_common_item
when: "__populate_credentials_list_common_item.controller_location is not defined"

- name: "Populate Credentials list by __site objects"
ansible.builtin.set_fact:
__populate_controller_credentials_site: "{{ (__populate_controller_credentials_site | default([])) + [__populate_credentials_list_site_item] }}"
loop: "{{ __populate_controller_credentials }}"
loop_control:
loop_var: __populate_credentials_list_site_item
when: "__populate_credentials_list_site_item.controller_location is defined and __populate_credentials_list_site_item.controller_location == controller_location"

- name: "Concatenate Credentials list common + site"
ansible.builtin.set_fact:
__populate_controller_credentials_total: "{{ __populate_controller_credentials_common | default([]) + __populate_controller_credentials_site }}"
when: __populate_controller_credentials_site is defined

- name: "Set Credentials Data Structure common + site concatenated"
ansible.builtin.set_fact:
__populate_controller_credentials: "{{ __populate_controller_credentials_total }}"
when: __populate_controller_credentials_total is defined

- name: "Set Credentials Data Structure"
ansible.builtin.set_fact:
Expand Down
41 changes: 37 additions & 4 deletions roles/filetree_read/tasks/execution_environments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,50 @@

- name: "Read Execution Environments definitions"
ansible.builtin.include_vars:
file: "{{ item.path }}"
file: "{{ __read_execution_environments_definitions_item.path }}"
loop: "{{ __list_files_controller_execution_environments.files }}"
loop_control:
loop_var: __read_execution_environments_definitions_item
register: __contents_filetree_controller_execution_environments

- name: "Populate Execution Environments list"
ansible.builtin.set_fact:
__populate_controller_execution_environments: "{{ (__populate_controller_execution_environments | default([])) + item.ansible_facts.controller_execution_environments }}"
__populate_controller_execution_environments: "{{ (__populate_controller_execution_environments | default([])) + __populate_execution_environments_list_item.ansible_facts.controller_execution_environments }}"
loop: "{{ __contents_filetree_controller_execution_environments.results }}"
when: __contents_filetree_controller_execution_environments.results is defined and item.ansible_facts.controller_execution_environments is defined
loop_control:
loop_var: __populate_execution_environments_list_item
when: __contents_filetree_controller_execution_environments.results is defined and __populate_execution_environments_list_item.ansible_facts.controller_execution_environments is defined

- name: "Set Projects Data Structure"
- name: "Segregated Execution Environments list when controller_location is defined"
when: controller_location is defined and __populate_controller_execution_environments is defined
block:
- name: "Populate Execution Environments list by _common objects"
ansible.builtin.set_fact:
__populate_controller_execution_environments_common: "{{ (__populate_controller_execution_environments_common | default([])) + [__populate_execution_environments_list_common_item] }}"
loop: "{{ __populate_controller_execution_environments }}"
loop_control:
loop_var: __populate_execution_environments_list_common_item
when: "__populate_execution_environments_list_common_item.controller_location is not defined"

- name: "Populate Execution Environments list by __site objects"
ansible.builtin.set_fact:
__populate_controller_execution_environments_site: "{{ (__populate_controller_execution_environments_site | default([])) + [__populate_execution_environments_list_site_item] }}"
loop: "{{ __populate_controller_execution_environments }}"
loop_control:
loop_var: __populate_execution_environments_list_site_item
when: "__populate_execution_environments_list_site_item.controller_location is defined and __populate_execution_environments_list_site_item.controller_location == controller_location"

- name: "Concatenate Execution Environments list common + site"
ansible.builtin.set_fact:
__populate_controller_execution_environments_total: "{{ __populate_controller_execution_environments_common | default([]) + __populate_controller_execution_environments_site }}"
when: __populate_controller_execution_environments_site is defined

- name: "Set Execution Environments Data Structure common + site concatenated"
ansible.builtin.set_fact:
__populate_controller_execution_environments: "{{ __populate_controller_execution_environments_total }}"
when: __populate_controller_execution_environments_total is defined

- name: "Set Execution Environments Data Structure"
ansible.builtin.set_fact:
controller_execution_environments: "{{ __populate_controller_execution_environments }}"
when: __populate_controller_execution_environments is defined
Expand Down
10 changes: 7 additions & 3 deletions roles/filetree_read/tasks/groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

- name: "Read Groups definitions"
ansible.builtin.include_vars:
file: "{{ item.path }}"
file: "{{ __read_groups_definitions_item.path }}"
loop: "{{ __list_files_controller_groups.files }}"
loop_control:
loop_var: __read_groups_definitions_item
register: __contents_filetree_controller_groups

- name: "Populate Groups list"
ansible.builtin.set_fact:
__populate_controller_groups: "{{ (__populate_controller_groups | default([])) + item.ansible_facts.controller_groups }}"
__populate_controller_groups: "{{ (__populate_controller_groups | default([])) + __populate_groups_list_item.ansible_facts.controller_groups }}"
loop: "{{ __contents_filetree_controller_groups.results }}"
when: __contents_filetree_controller_groups.results is defined and item.ansible_facts.controller_groups is defined
loop_control:
loop_var: __populate_groups_list_item
when: __contents_filetree_controller_groups.results is defined and __populate_groups_list_item.ansible_facts.controller_groups is defined

- name: "Set Groups Data Structure"
ansible.builtin.set_fact:
Expand Down
41 changes: 37 additions & 4 deletions roles/filetree_read/tasks/hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,50 @@

- name: "Read Hosts definitions"
ansible.builtin.include_vars:
file: "{{ item.path }}"
file: "{{ __read_hosts_definitions_item.path }}"
loop: "{{ __list_files_controller_hosts.files }}"
loop_control:
loop_var: __read_hosts_definitions_item
register: __contents_filetree_controller_hosts

- name: "Populate Hosts list"
ansible.builtin.set_fact:
__populate_controller_hosts: "{{ (__populate_controller_hosts | default([])) + item.ansible_facts.controller_hosts }}"
__populate_controller_hosts: "{{ (__populate_controller_hosts | default([])) + __populate_hosts_list_item.ansible_facts.controller_hosts }}"
loop: "{{ __contents_filetree_controller_hosts.results }}"
when: __contents_filetree_controller_hosts.results is defined and item.ansible_facts.controller_hosts is defined
loop_control:
loop_var: __populate_hosts_list_item
when: __contents_filetree_controller_hosts.results is defined and __populate_hosts_list_item.ansible_facts.controller_hosts is defined

- name: "Set Projects Data Structure"
- name: "Segregated Hosts list when controller_location is defined"
when: controller_location is defined and __populate_controller_hosts is defined
block:
- name: "Populate Hosts list by _common objects"
ansible.builtin.set_fact:
__populate_controller_hosts_common: "{{ (__populate_controller_hosts_common | default([])) + [__populate_hosts_list_common_item] }}"
loop: "{{ __populate_controller_hosts }}"
loop_control:
loop_var: __populate_hosts_list_common_item
when: "__populate_hosts_list_common_item.controller_location is not defined"

- name: "Populate Hosts list by __site objects"
ansible.builtin.set_fact:
__populate_controller_hosts_site: "{{ (__populate_controller_hosts_site | default([])) + [__populate_hosts_list_site_item] }}"
loop: "{{ __populate_controller_hosts }}"
loop_control:
loop_var: __populate_hosts_list_site_item
when: "__populate_hosts_list_site_item.controller_location is defined and __populate_hosts_list_site_item.controller_location == controller_location"

- name: "Concatenate Hosts list common + site"
ansible.builtin.set_fact:
__populate_controller_hosts_total: "{{ __populate_controller_hosts_common | default([]) + __populate_controller_hosts_site }}"
when: __populate_controller_hosts_site is defined

- name: "Set Hosts Data Structure common + site concatenated"
ansible.builtin.set_fact:
__populate_controller_hosts: "{{ __populate_controller_hosts_total }}"
when: __populate_controller_hosts_total is defined

- name: "Set Hosts Data Structure"
ansible.builtin.set_fact:
controller_hosts: "{{ __populate_controller_hosts }}"
when: __populate_controller_hosts is defined
Expand Down
39 changes: 36 additions & 3 deletions roles/filetree_read/tasks/instance_groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,48 @@

- name: "Read Instance Groups definitions"
ansible.builtin.include_vars:
file: "{{ item.path }}"
file: "{{ __read_instance_groups_definitions_item.path }}"
loop: "{{ __list_files_controller_instance_groups.files }}"
loop_control:
loop_var: __read_instance_groups_definitions_item
register: __contents_filetree_controller_instance_groups

- name: "Populate Instance Groups list"
ansible.builtin.set_fact:
__populate_controller_instance_groups: "{{ (__populate_controller_instance_groups | default([])) + item.ansible_facts.controller_instance_groups }}"
__populate_controller_instance_groups: "{{ (__populate_controller_instance_groups | default([])) + __populate_instance_groups_list_item.ansible_facts.controller_instance_groups }}"
loop: "{{ __contents_filetree_controller_instance_groups.results }}"
when: __contents_filetree_controller_instance_groups.results is defined and item.ansible_facts.controller_instance_groups is defined
loop_control:
loop_var: __populate_instance_groups_list_item
when: __contents_filetree_controller_instance_groups.results is defined and __populate_instance_groups_list_item.ansible_facts.controller_instance_groups is defined

- name: "Segregated Instance Groups list when controller_location is defined"
when: controller_location is defined and __populate_controller_instance_groups is defined
block:
- name: "Populate Instance Groups list by _common objects"
ansible.builtin.set_fact:
__populate_controller_instance_groups_common: "{{ (__populate_controller_instance_groups_common | default([])) + [__populate_instance_groups_list_common_item] }}"
loop: "{{ __populate_controller_instance_groups }}"
loop_control:
loop_var: __populate_instance_groups_list_common_item
when: "__populate_instance_groups_list_common_item.controller_location is not defined"

- name: "Populate Instance Groups list by __site objects"
ansible.builtin.set_fact:
__populate_controller_instance_groups_site: "{{ (__populate_controller_instance_groups_site | default([])) + [__populate_instance_groups_list_site_item] }}"
loop: "{{ __populate_controller_instance_groups }}"
loop_control:
loop_var: __populate_instance_groups_list_site_item
when: "__populate_instance_groups_list_site_item.controller_location is defined and __populate_instance_groups_list_site_item.controller_location == controller_location"

- name: "Concatenate Instance Groups list common + site"
ansible.builtin.set_fact:
__populate_controller_instance_groups_total: "{{ __populate_controller_instance_groups_common | default([]) + __populate_controller_instance_groups_site }}"
when: __populate_controller_instance_groups_site is defined

- name: "Set Instance Groups Data Structure common + site concatenated"
ansible.builtin.set_fact:
__populate_controller_instance_groups: "{{ __populate_controller_instance_groups_total }}"
when: __populate_controller_instance_groups_total is defined

- name: "Set Instance Groups Data Structure"
ansible.builtin.set_fact:
Expand Down
10 changes: 7 additions & 3 deletions roles/filetree_read/tasks/inventories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

- name: "Read Inventories definitions"
ansible.builtin.include_vars:
file: "{{ item.path }}"
file: "{{ __read_inventories_definitions_item.path }}"
loop: "{{ __list_files_controller_inventories.files }}"
loop_control:
loop_var: __read_inventories_definitions_item
register: __contents_filetree_controller_inventories

- name: "Populate Inventories list"
ansible.builtin.set_fact:
__populate_controller_inventories: "{{ (__populate_controller_inventories | default([])) + item.ansible_facts.controller_inventories }}"
__populate_controller_inventories: "{{ (__populate_controller_inventories | default([])) + __populate_inventories_list_item.ansible_facts.controller_inventories }}"
loop: "{{ __contents_filetree_controller_inventories.results }}"
when: __contents_filetree_controller_inventories.results is defined and item.ansible_facts.controller_inventories is defined
loop_control:
loop_var: __populate_inventories_list_item
when: __contents_filetree_controller_inventories.results is defined and __populate_inventories_list_item.ansible_facts.controller_inventories is defined

- name: "Set Inventories Data Structure"
ansible.builtin.set_fact:
Expand Down
Loading

0 comments on commit 5b3eb8c

Please sign in to comment.