Skip to content

Commit e335ed0

Browse files
authored
Merge pull request #3 from adonisgarciac/desired_jt_teams_org
Fix: desired_state remove only objects of its org
2 parents bfdb83b + ce126f4 commit e335ed0

File tree

4 files changed

+96
-66
lines changed

4 files changed

+96
-66
lines changed

roles/controller_casc_desired_state/tasks/job_templates_desired_state.yml

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,40 @@
2020

2121
when: orgs is defined and dir_orgs_vars is defined
2222

23-
- name: "DESIRED STATE: Get the API list of all Job Templates"
24-
set_fact:
25-
__controller_api_job_templates: "{{ query('ansible.controller.controller_api', 'job_templates',
26-
host=controller_hostname, username=controller_username,
27-
password=controller_password, verify_ssl=false) }}"
28-
29-
- debug:
30-
var: "{{ item }}"
31-
loop:
32-
- __controller_api_job_templates
33-
34-
- name: "DESIRED STATE: Find the difference of Job Templates between what is on the Controller versus CasC on SCM"
35-
set_fact:
36-
__job_templates_difference: "{{ lookup('redhat_cop.controller_casc.controller_object_diff_temp',
37-
api_list=__controller_api_job_templates, compare_list=controller_templates,
38-
with_present=false, set_absent=true ) }}"
39-
40-
- debug:
41-
var: "{{ item }}"
42-
loop:
43-
- __job_templates_difference
44-
45-
- name: "DESIRED STATE: Set job_template's list to be configured"
46-
set_fact:
47-
controller_templates: "{{ __job_templates_difference }}"
48-
49-
- name: "DESIRED STATE: Configure Controller Job Templates"
50-
import_role:
51-
name: redhat_cop.controller_configuration.job_templates
23+
- block:
24+
25+
- name: Get the organization ID
26+
set_fact:
27+
__controller_organization_id: "{{ lookup('ansible.controller.controller_api', 'organizations', query_params={ 'name': orgs },
28+
host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
29+
30+
- name: "DESIRED STATE: Get the API list of all Job Templates {{ orgs }} Organization"
31+
set_fact:
32+
__controller_api_job_templates: "{{ query('ansible.controller.controller_api', 'job_templates',
33+
query_params={ 'organization': __controller_organization_id.id },
34+
host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
35+
36+
- debug:
37+
var: "{{ item }}"
38+
loop:
39+
- __controller_api_job_templates
40+
41+
- name: "DESIRED STATE: Find the difference of Job Templates between what is on the Controller versus CasC on SCM"
42+
set_fact:
43+
__job_templates_difference: "{{ lookup('redhat_cop.controller_casc.controller_object_diff_temp',
44+
api_list=__controller_api_job_templates, compare_list=controller_templates,
45+
with_present=false, set_absent=true ) }}"
46+
47+
- debug:
48+
var: "{{ item }}"
49+
loop:
50+
- __job_templates_difference
51+
52+
- name: "DESIRED STATE: Set job_template's list to be configured"
53+
set_fact:
54+
controller_templates: "{{ __job_templates_difference }}"
55+
56+
- name: "DESIRED STATE: Configure Controller Job Templates"
57+
import_role:
58+
name: redhat_cop.controller_configuration.job_templates
5259
...

roles/controller_casc_desired_state/tasks/teams_desired_state.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525
__controller_api_current_user_check_is_admin: "{{ lookup('ansible.controller.controller_api', 'users', query_params={ 'username': controller_username },
2626
host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
2727
- block:
28+
- name: Get the organization ID
29+
set_fact:
30+
__controller_organization_id: "{{ lookup('ansible.controller.controller_api', 'organizations', query_params={ 'name': orgs },
31+
host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
2832

29-
- name: "DESIRED STATE: Get the API list of all teams"
33+
- name: "DESIRED STATE: Get the API list of all teams {{ orgs }} Organization"
3034
set_fact:
3135
__controller_api_teams: "{{ query('ansible.controller.controller_api', 'teams',
32-
host=controller_hostname, username=controller_username,
33-
password=controller_password, verify_ssl=false) }}"
36+
query_params={ 'organization': __controller_organization_id.id },
37+
host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
3438

3539
- debug:
3640
msg: "{{ __controller_api_teams }}"

roles/controller_casc_desired_state/tasks/workflow_job_template_nodes_desired_state.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,24 @@
2020

2121
when: orgs is defined and dir_orgs_vars is defined
2222

23-
- name: "DESIRED STATE: Get the API list of all Workflow Job Template Nodes"
24-
set_fact:
25-
__controller_api_workflow_job_template_nodes: "{{ query('ansible.controller.controller_api', 'workflow_job_template_nodes',
26-
host=controller_hostname, username=controller_username,
27-
password=controller_password, verify_ssl=false) }}"
23+
- block:
24+
25+
- name: Get the organization ID
26+
set_fact:
27+
__controller_organization_id: "{{ lookup('ansible.controller.controller_api', 'organizations', query_params={ 'name': orgs },
28+
host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
29+
30+
- name: "DESIRED STATE: Get ID of the API list of all Workflow Job Templates {{ orgs }} Organization"
31+
set_fact:
32+
__controller_api_workflow_job_templates_id: "{{ query('ansible.controller.controller_api', 'workflow_job_templates',
33+
query_params={ 'organization': __controller_organization_id.id },
34+
host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) | selectattr('id', 'defined') | map(attribute='id') }}"
35+
36+
- name: "DESIRED STATE: Get the API list of all Workflow Job Template Nodes {{ orgs }} Organization"
37+
set_fact:
38+
__controller_api_workflow_job_template_nodes: "{{ query('ansible.controller.controller_api', 'workflow_job_template_nodes',
39+
host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) | selectattr('workflow_job_template', 'defined') | selectattr('workflow_job_template','in',__controller_api_workflow_job_templates_id) }}"
40+
2841
- block:
2942
- debug:
3043
var: "{{ item }}"

roles/controller_casc_desired_state/tasks/workflow_job_templates_desired_state.yml

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,39 @@
2020

2121
when: dir_orgs_vars is defined and orgs is defined
2222

23-
- name: "DESIRED STATE: Get the API list of all Workflow Job Templates"
24-
set_fact:
25-
__controller_api_workflow_job_templates: "{{ query('ansible.controller.controller_api', 'workflow_job_templates',
26-
host=controller_hostname, username=controller_username,
27-
password=controller_password, verify_ssl=false) }}"
28-
29-
- debug:
30-
var: "{{ item }}"
31-
loop:
32-
- __controller_api_workflow_job_templates
33-
34-
- name: "DESIRED STATE: Find the difference of Workflow Job Templates between what is on the Controller versus CasC on SCM"
35-
set_fact:
36-
__workflow_job_templates_difference: "{{ lookup('redhat_cop.controller_casc.controller_object_diff_temp',
37-
api_list=__controller_api_workflow_job_templates, compare_list=controller_workflows,
38-
with_present=false, set_absent=true ) }}"
39-
40-
- debug:
41-
var: "{{ item }}"
42-
loop:
43-
- __workflow_job_templates_difference
44-
45-
- name: "DESIRED STATE: Set job_template's list to be configured"
46-
set_fact:
47-
controller_workflows: "{{ __workflow_job_templates_difference }}"
48-
49-
- name: "DESIRED STATE: Configure Controller Workflow Job Templates"
50-
import_role:
51-
name: redhat_cop.controller_configuration.workflow_job_templates
23+
- block:
24+
- name: Get the organization ID
25+
set_fact:
26+
__controller_organization_id: "{{ lookup('ansible.controller.controller_api', 'organizations', query_params={ 'name': orgs },
27+
host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
28+
29+
- name: "DESIRED STATE: Get the API list of all Workflow Job Templates"
30+
set_fact:
31+
__controller_api_workflow_job_templates: "{{ query('ansible.controller.controller_api', 'workflow_job_templates',
32+
query_params={ 'organization': __controller_organization_id.id },
33+
host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
34+
35+
- debug:
36+
var: "{{ item }}"
37+
loop:
38+
- __controller_api_workflow_job_templates
39+
40+
- name: "DESIRED STATE: Find the difference of Workflow Job Templates between what is on the Controller versus CasC on SCM"
41+
set_fact:
42+
__workflow_job_templates_difference: "{{ lookup('redhat_cop.controller_casc.controller_object_diff_temp',
43+
api_list=__controller_api_workflow_job_templates, compare_list=controller_workflows,
44+
with_present=false, set_absent=true ) }}"
45+
46+
- debug:
47+
var: "{{ item }}"
48+
loop:
49+
- __workflow_job_templates_difference
50+
51+
- name: "DESIRED STATE: Set job_template's list to be configured"
52+
set_fact:
53+
controller_workflows: "{{ __workflow_job_templates_difference }}"
54+
55+
- name: "DESIRED STATE: Configure Controller Workflow Job Templates"
56+
import_role:
57+
name: redhat_cop.controller_configuration.workflow_job_templates
5258
...

0 commit comments

Comments
 (0)