Skip to content

Commit

Permalink
feat: use global var and remove group facts
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayuchen888 committed Jul 18, 2024
1 parent 984d986 commit 0038ad9
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 156 deletions.
10 changes: 5 additions & 5 deletions roles/satellite/tasks/define.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
- include_tasks:
file: internals/contentview-promote.yml
vars:
target_lce_name: "{{ g_test_lifecycleenvironment }}"
target_lce_name: "{{ test_lifecycleenvironment }}"
source_lce_name: Library
when: g_test_lifecycleenvironment_defined
when: test_lifecycleenvironment_defined

# promote contentview from test->prod
- include_tasks:
file: internals/contentview-promote.yml
vars:
target_lce_name: "{{ g_prod_lifecycleenvironment }}"
source_lce_name: "{{ g_test_lifecycleenvironment }}"
when: g_test_lifecycleenvironment_defined and g_prod_lifecycleenvironment_defined
target_lce_name: "{{ prod_lifecycleenvironment }}"
source_lce_name: "{{ test_lifecycleenvironment }}"
when: test_lifecycleenvironment_defined and prod_lifecycleenvironment_defined

- include_tasks:
file: internals/activationkey-hostgroup-definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
password: "{{ satellite_pwd }}"
server_url: "{{ satellite_url }}"
validate_certs: "{{ satellite_verify_ssl }}"
name: "{{ g_test_activationkey }}"
name: "{{ test_activationkey }}"
content_view: "{{ deploymentcontentview }}"
lifecycle_environment: "{{ g_test_lifecycleenvironment }}"
lifecycle_environment: "{{ test_lifecycleenvironment }}"
subscriptions: "{{ subscriptions | default(omit) }}"
content_overrides: "{{ contentoverrides | default(omit) }}"
auto_attach: True
organization: "{{ satellite_organization }}"
when: g_test_lifecycleenvironment_defined and g_test_activationkey_defined
when: test_lifecycleenvironment_defined and test_activationkey_defined

- name: "Define hostgroup for test"
theforeman.foreman.hostgroup:
Expand All @@ -20,40 +20,40 @@
server_url: "{{ satellite_url }}"
validate_certs: "{{ satellite_verify_ssl }}"

name: "{{ g_test_hostgroup }}"
name: "{{ test_hostgroup }}"
organization: "{{ satellite_organization }}"
organizations:
- "{{ satellite_organization }}"
domain: "{{ hostvars[groups['test'][0]]['domain'] if g_test_domain_is_groupvar else test_domain | default(omit) }}"
architecture: "{{ hostvars[groups['test'][0]]['architecture'] if g_test_architecture_is_groupvar else test_architecture | default(omit) }}"
ptable: "{{ hostvars[groups['test'][0]]['partition_table'] if g_test_partition_table_is_groupvar else test_partition_table | default(omit) }}"
operatingsystem: "{{ hostvars[groups['test'][0]]['operatingsystem'] if g_test_operatingsystem_is_groupvar else test_operatingsystem | default(omit) }}"
medium: "{{ hostvars[groups['test'][0]]['provision_installation_media'] if g_test_medium_is_groupvar else test_provision_installation_media | default(omit) }}"
content_source: "{{ hostvars[groups['test'][0]]['foreman_capsule'] if g_test_foreman_capsule_is_groupvar else test_foreman_capsule | default(omit) }}"
lifecycle_environment: "{{ g_test_lifecycleenvironment }}"
parent: "{{ hostvars[groups['test'][0]]['hostgroup_parent'] if g_test_hostgroup_parent_is_groupvar else test_hostgroup_parent | default(omit) }}"
pxe_loader: "{{ hostvars[groups['test'][0]]['pxe_loader'] if g_test_pxe_loader_is_groupvar else test_pxe_loader | default(omit) }}"
domain: "{{ test_domain | default(omit) }}"
architecture: "{{ test_architecture | default(omit) }}"
ptable: "{{ test_partition_table | default(omit) }}"
operatingsystem: "{{ test_operatingsystem | default(omit) }}"
medium: "{{ test_provision_installation_media | default(omit) }}"
content_source: "{{ test_foreman_capsule | default(omit) }}"
lifecycle_environment: "{{ test_lifecycleenvironment }}"
parent: "{{ test_hostgroup_parent | default(omit) }}"
pxe_loader: "{{ test_pxe_loader | default(omit) }}"
locations: "{{ locations.keys() | list }}"
parameters:
- name: "kt_activation_keys"
value: "{{ g_test_activationkey }}"
value: "{{ test_activationkey }}"
content_view: "{{ deploymentcontentview }}"
when: g_test_lifecycleenvironment_defined and g_test_activationkey_defined and g_test_hostgroup_defined
when: test_lifecycleenvironment_defined and test_activationkey_defined and test_hostgroup_defined

- name: "Define Activation Key for production"
theforeman.foreman.activation_key:
username: "{{ satellite_user }}"
password: "{{ satellite_pwd }}"
server_url: "{{ satellite_url }}"
validate_certs: "{{ satellite_verify_ssl }}"
name: "{{ g_prod_activationkey }}"
name: "{{ prod_activationkey }}"
content_view: "{{ deploymentcontentview }}"
lifecycle_environment: "{{ g_prod_lifecycleenvironment }}"
lifecycle_environment: "{{ prod_lifecycleenvironment }}"
subscriptions: "{{ subscriptions | default(omit) }}"
content_overrides: "{{ contentoverrides | default(omit) }}"
auto_attach: True
organization: "{{ satellite_organization }}"
when: g_prod_lifecycleenvironment_defined and g_prod_activationkey_defined
when: prod_lifecycleenvironment_defined and prod_activationkey_defined

- name: "Define hostgroup for production"
theforeman.foreman.hostgroup:
Expand All @@ -62,22 +62,22 @@
server_url: "{{ satellite_url }}"
validate_certs: "{{ satellite_verify_ssl }}"

name: "{{ g_prod_hostgroup }}"
name: "{{ prod_hostgroup }}"
organization: "{{ satellite_organization }}"
organizations:
- "{{ satellite_organization }}"
domain: "{{ hostvars[groups['prod'][0]]['domain'] if g_prod_domain_is_groupvar else prod_domain | default(omit) }}"
architecture: "{{ hostvars[groups['prod'][0]]['architecture'] if g_prod_architecture_is_groupvar else prod_architecture | default(omit) }}"
ptable: "{{ hostvars[groups['prod'][0]]['partition_table'] if g_prod_partition_table_is_groupvar else prod_partition_table | default(omit) }}"
operatingsystem: "{{ hostvars[groups['prod'][0]]['operatingsystem'] if g_prod_operatingsystem_is_groupvar else prod_operatingsystem | default(omit) }}"
medium: "{{ hostvars[groups['prod'][0]]['provision_installation_media'] if g_prod_medium_is_groupvar else prod_provision_installation_media | default(omit) }}"
content_source: "{{ hostvars[groups['prod'][0]]['foreman_capsule'] if g_prod_foreman_capsule_is_groupvar else prod_foreman_capsule | default(omit) }}"
lifecycle_environment: "{{ g_prod_lifecycleenvironment }}"
parent: "{{ hostvars[groups['prod'][0]]['hostgroup_parent'] if g_prod_hostgroup_parent_is_groupvar else prod_hostgroup_parent | default(omit) }}"
pxe_loader: "{{ hostvars[groups['prod'][0]]['pxe_loader'] if g_prod_pxe_loader_is_groupvar else prod_pxe_loader | default(omit) }}"
domain: "{{ prod_domain | default(omit) }}"
architecture: "{{ prod_architecture | default(omit) }}"
ptable: "{{ prod_partition_table | default(omit) }}"
operatingsystem: "{{ prod_operatingsystem | default(omit) }}"
medium: "{{ prod_provision_installation_media | default(omit) }}"
content_source: "{{ prod_foreman_capsule | default(omit) }}"
lifecycle_environment: "{{ prod_lifecycleenvironment }}"
parent: "{{ prod_hostgroup_parent | default(omit) }}"
pxe_loader: "{{ prod_pxe_loader | default(omit) }}"
locations: "{{ locations.keys() | list }}"
parameters:
- name: "kt_activation_keys"
value: "{{ g_prod_activationkey }}"
value: "{{ prod_activationkey }}"
content_view: "{{ deploymentcontentview }}"
when: g_prod_lifecycleenvironment_defined and g_prod_activationkey_defined and g_prod_hostgroup_defined
when: prod_lifecycleenvironment_defined and prod_activationkey_defined and prod_hostgroup_defined
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
server_url: "{{ satellite_url }}"
validate_certs: "{{ satellite_verify_ssl }}"

name: "{{ g_prod_hostgroup }}"
name: "{{ prod_hostgroup }}"
organization: "{{ satellite_organization }}"
organizations:
- "{{ satellite_organization }}"
domain: "{{ hostvars[groups['prod'][0]]['domain'] if g_prod_domain_is_groupvar else prod_domain | default(omit) }}"
architecture: "{{ hostvars[groups['prod'][0]]['architecture'] if g_prod_architecture_is_groupvar else prod_architecture | default(omit) }}"
ptable: "{{ hostvars[groups['prod'][0]]['partition_table'] if g_prod_partition_table_is_groupvar else prod_partition_table | default(omit) }}"
operatingsystem: "{{ hostvars[groups['prod'][0]]['operatingsystem'] if g_prod_operatingsystem_is_groupvar else prod_operatingsystem | default(omit) }}"
medium: "{{ hostvars[groups['prod'][0]]['provision_installation_media'] if g_prod_medium_is_groupvar else prod_provision_installation_media | default(omit) }}"
content_source: "{{ hostvars[groups['prod'][0]]['foreman_capsule'] if g_prod_foreman_capsule_is_groupvar else prod_foreman_capsule | default(omit) }}"
lifecycle_environment: "{{ g_prod_lifecycleenvironment }}"
parent: "{{ hostvars[groups['prod'][0]]['hostgroup_parent'] if g_prod_hostgroup_parent_is_groupvar else prod_hostgroup_parent | default(omit) }}"
pxe_loader: "{{ hostvars[groups['prod'][0]]['pxe_loader'] if g_prod_pxe_loader_is_groupvar else prod_pxe_loader | default(omit) }}"
domain: "{{ prod_domain | default(omit) }}"
architecture: "{{ prod_architecture | default(omit) }}"
ptable: "{{ prod_partition_table | default(omit) }}"
operatingsystem: "{{ prod_operatingsystem | default(omit) }}"
medium: "{{ prod_provision_installation_media | default(omit) }}"
content_source: "{{ prod_foreman_capsule | default(omit) }}"
lifecycle_environment: "{{ prod_lifecycleenvironment }}"
parent: "{{ prod_hostgroup_parent | default(omit) }}"
pxe_loader: "{{ prod_pxe_loader | default(omit) }}"
locations: "{{ locations.keys() | list }}"
parameters:
- name: "kt_activation_keys"
value: "{{ g_prod_activationkey }}"
value: "{{ prod_activationkey }}"
content_view: "{{ deploymentcontentview }}"
state: absent
when: g_prod_lifecycleenvironment_defined and g_prod_activationkey_defined and g_prod_activationkey_defined
when: prod_lifecycleenvironment_defined and prod_activationkey_defined and prod_activationkey_defined
ignore_errors: yes

- name: "Deprovision Activation Key for production"
Expand All @@ -33,44 +33,43 @@
password: "{{ satellite_pwd }}"
server_url: "{{ satellite_url }}"
validate_certs: "{{ satellite_verify_ssl }}"
name: "{{ g_prod_activationkey }}"
name: "{{ prod_activationkey }}"
content_view: "{{ deploymentcontentview }}"
lifecycle_environment: "{{ g_prod_lifecycleenvironment }}"
lifecycle_environment: "{{ prod_lifecycleenvironment }}"
subscriptions: "{{ subscriptions | default(omit) }}"
content_overrides: "{{ contentoverrides | default(omit) }}"
auto_attach: True
organization: "{{ satellite_organization }}"
state: absent
ignore_errors: yes
when: g_prod_lifecycleenvironment_defined and g_prod_activationkey_defined
when: prod_lifecycleenvironment_defined and prod_activationkey_defined

- name: "Deprovision hostgroup for test"
theforeman.foreman.hostgroup:
username: "{{ satellite_user }}"
password: "{{ satellite_pwd }}"
server_url: "{{ satellite_url }}"
validate_certs: "{{ satellite_verify_ssl }}"

name: "{{ g_test_hostgroup }}"
name: "{{ test_hostgroup }}"
organization: "{{ satellite_organization }}"
organizations:
- "{{ satellite_organization }}"
domain: "{{ hostvars[groups['test'][0]]['domain'] if g_test_domain_is_groupvar else test_domain | default(omit) }}"
architecture: "{{ hostvars[groups['test'][0]]['architecture'] if g_test_architecture_is_groupvar else test_architecture | default(omit) }}"
ptable: "{{ hostvars[groups['test'][0]]['partition_table'] if g_test_partition_table_is_groupvar else test_partition_table | default(omit) }}"
operatingsystem: "{{ hostvars[groups['test'][0]]['operatingsystem'] if g_test_operatingsystem_is_groupvar else test_operatingsystem | default(omit) }}"
medium: "{{ hostvars[groups['test'][0]]['provision_installation_media'] if g_test_medium_is_groupvar else test_provision_installation_media | default(omit) }}"
content_source: "{{ hostvars[groups['test'][0]]['foreman_capsule'] if g_test_foreman_capsule_is_groupvar else test_foreman_capsule | default(omit) }}"
lifecycle_environment: "{{ g_test_lifecycleenvironment }}"
parent: "{{ hostvars[groups['test'][0]]['hostgroup_parent'] if g_test_hostgroup_parent_is_groupvar else test_hostgroup_parent | default(omit) }}"
pxe_loader: "{{ hostvars[groups['test'][0]]['pxe_loader'] if g_test_pxe_loader_is_groupvar else test_pxe_loader | default(omit) }}"
domain: "{{ test_domain | default(omit) }}"
architecture: "{{ test_architecture | default(omit) }}"
ptable: "{{ test_partition_table | default(omit) }}"
operatingsystem: "{{ test_operatingsystem | default(omit) }}"
medium: "{{ test_provision_installation_media | default(omit) }}"
content_source: "{{ test_foreman_capsule | default(omit) }}"
lifecycle_environment: "{{ test_lifecycleenvironment }}"
parent: "{{ test_hostgroup_parent | default(omit) }}"
pxe_loader: "{{ test_pxe_loader | default(omit) }}"
locations: "{{ locations.keys() | list }}"
parameters:
- name: "kt_activation_keys"
value: "{{ g_test_activationkey }}"
value: "{{ test_activationkey }}"
content_view: "{{ deploymentcontentview }}"
state: absent
when: g_test_lifecycleenvironment_defined and g_test_activationkey_defined and g_test_hostgroup_defined
when: test_lifecycleenvironment_defined and test_activationkey_defined and test_hostgroup_defined
ignore_errors: yes

- name: "Delete Activation Key for test"
Expand All @@ -79,13 +78,13 @@
password: "{{ satellite_pwd }}"
server_url: "{{ satellite_url }}"
validate_certs: "{{ satellite_verify_ssl }}"
name: "{{ g_test_activationkey }}"
name: "{{ test_activationkey }}"
content_view: "{{ deploymentcontentview }}"
lifecycle_environment: "{{ g_test_lifecycleenvironment }}"
lifecycle_environment: "{{ test_lifecycleenvironment }}"
subscriptions: "{{ subscriptions | default(omit) }}"
content_overrides: "{{ contentoverrides | default(omit) }}"
auto_attach: True
organization: "{{ satellite_organization }}"
state: absent
ignore_errors: yes
when: g_test_lifecycleenvironment_defined and g_test_activationkey_defined
when: test_lifecycleenvironment_defined and test_activationkey_defined
Loading

0 comments on commit 0038ad9

Please sign in to comment.