Skip to content

Commit

Permalink
Merge pull request #6 from plajusticia/refactor_projects
Browse files Browse the repository at this point in the history
Refactor projects
  • Loading branch information
ivarmu authored Jul 7, 2022
2 parents 91a6a45 + 26095c5 commit b65b7be
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace: redhat_cop
name: controller_casc

# The version of the collection. Must be compatible with semantic versioning
version: 0.0.150
version: 0.0.151

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
9 changes: 6 additions & 3 deletions roles/controller_casc_from_aap/tasks/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
### job_templates: "{{ 'all' if ('all' in input_tag or 'job_templates' in input_tag) else omit }}"
notification_templates: "{{ 'all' if ('all' in input_tag or 'notification_templates' in input_tag) else omit }}"
### organizations: "{{ 'all' if ('all' in input_tag or 'organizations' in input_tag) else omit }}"
projects: "{{ 'all' if ('all' in input_tag or 'projects' in input_tag) else omit }}"
### projects: "{{ 'all' if ('all' in input_tag or 'projects' in input_tag) else omit }}"
# roles: "{{ 'all' if ('all' in input_tag or 'roles' in input_tag) else omit }}"
teams: "{{ 'all' if ('all' in input_tag or 'teams' in input_tag) else omit }}"
users: "{{ 'all' if ('all' in input_tag or 'users' in input_tag) else omit }}"
Expand All @@ -37,7 +37,7 @@
loop_control:
loop_var: asset_item
label: asset_item
when: "['all', 'credentials', 'credential_types', 'execution_environments', 'inventory_sources', 'notification_templates', 'projects', 'teams', 'users'] | intersect(input_tag) | length > 0"
when: "['all', 'credentials', 'credential_types', 'execution_environments', 'inventory_sources', 'notification_templates', 'teams', 'users'] | intersect(input_tag) | length > 0"

- block:
- name: "Export Inventories and related Groups and Hosts"
Expand All @@ -52,11 +52,14 @@
- name: "Export Workflow Job Templates"
include_tasks: "workflow_job_templates_from_aap_improved.yml"
when: "'workflow_job_templates' in input_tag or 'all' in input_tag"
- name: "Export Projects"
include_tasks: "projects_from_aap_improved.yml"
when: "'projects' in input_tag or 'all' in input_tag"
- name: "Export Workflow Job Template Nodes"
# Do not run if 'all' is in input_tag, as it will be called from workflow_job_templates_from_aap_improved.yml
include_tasks: "workflow_job_template_nodes_from_aap_improved.yml"
when:
- "'workflow_job_template_nodes' in input_tag"
- "'workflow_job_templates' not in input_tag"
when: "['all', 'inventory', 'organizations', 'job_templates', 'workflow_job_templates', 'workflow_job_template_nodes'] | intersect(input_tag) | length > 0"
when: "['all', 'inventory', 'organizations', 'job_templates', 'workflow_job_templates', 'workflow_job_template_nodes','projects'] | intersect(input_tag) | length > 0"
...
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
src: "templates/current_job_templates_improved.j2"
dest: "{{ output_path }}/current_job_templates.yaml"
vars:
current_jt_asset_value: "{{ jt_lookvar }}"
current_job_templates_asset_value: "{{ jt_lookvar }}"
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: "Get current Projects from the API"
set_fact:
projects_lookvar: "{{ query('ansible.controller.controller_api', 'api/v2/projects/', host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=controller_validate_certs, return_all=true) }}"

- name: "Create the output directory: {{ output_path }}"
file:
path: "{{ output_path }}"
state: directory

- name: "Add current projects to the output yaml file: {{ output_path }}/current_projects.yaml"
template:
src: "templates/current_projects_improved.j2"
dest: "{{ output_path }}/current_projects.yaml"
vars:
current_projects_asset_value: "{{ projects_lookvar }}"
...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
controller_templates:
{% for job_template in current_jt_asset_value %}
{% for job_template in current_job_templates_asset_value %}
- name: "{{ job_template.name }}"
description: "{{ job_template.description }}"
organization: "{{ job_template.summary_fields.organization.name | default('ToDo: The job template \'' + job_template.name + '\' must belong to an organization') }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
controller_projects:
{% for project in current_projects_asset_value %}
- name: "{{ project.name }}"
description: "{{ project.description }}"
organization: "{{ project.summary_fields.organization.name | default('ToDo: The project \'' + project.name + '\' must have an organization') }}"
{% if project.scm_type %}
scm_type: "{{ project.scm_type }}"
scm_url: "{{ project.scm_url }}"
scm_credential: "{{ project.summary_fields.credential.name | default('ToDo: The project \'' + project.name + '\' is missing the SCM credential') }}"
scm_branch: "{{ project.scm_branch }}"
scm_clean: "{{ project.scm_clean }}"
scm_delete_on_update: "{{ project.scm_delete_on_update }}"
scm_update_on_launch: "{{ project.scm_update_on_launch }}"
scm_update_cache_timeout: "{{ project.scm_update_cache_timeout }}"
{% endif %}
allow_override: "{{ project.allow_override }}"
timeout: {{ project.timeout }}
{% endfor %}
...

0 comments on commit b65b7be

Please sign in to comment.