| 1 |
--- |
| 2 |
- hosts: localhost |
| 3 |
collections: |
| 4 |
- theforeman.foreman |
| 5 |
gather_facts: false |
| 6 |
vars_files: |
| 7 |
- vars/server.yml |
| 8 |
- vars/hostgroup.yml |
| 9 |
tasks: |
| 10 |
- include_tasks: tasks/location.yml |
| 11 |
vars: |
| 12 |
location_name: "{{ item }}" |
| 13 |
location_state: present |
| 14 |
with_items: "{{ hostgroup.locations }}" |
| 15 |
- include_tasks: tasks/organization.yml |
| 16 |
vars: |
| 17 |
organization_name: "{{ item }}" |
| 18 |
organization_state: present |
| 19 |
with_items: "{{ hostgroup.organizations }}" |
| 20 |
- include_tasks: tasks/content_view.yml |
| 21 |
vars: |
| 22 |
organization_name: "{{ hostgroup.organizations | first }}" |
| 23 |
content_view_name: "{{ hostgroup.content_view.name }}" |
| 24 |
- include_tasks: tasks/content_view_version.yml |
| 25 |
vars: |
| 26 |
organization_name: "{{ hostgroup.organizations | first }}" |
| 27 |
content_view_name: "{{ hostgroup.content_view.name }}" |
| 28 |
lifecycle_environments: "{{ hostgroup.lifecycle_environment }}" |
| 29 |
version: "{{ hostgroup.content_view.version }}" |
| 30 |
- include_tasks: tasks/hostgroup.yml |
| 31 |
vars: |
| 32 |
hostgroup_name: "New host group" |
| 33 |
hostgroup_state: absent |
| 34 |
|
| 35 |
- hosts: tests |
| 36 |
collections: |
| 37 |
- theforeman.foreman |
| 38 |
gather_facts: false |
| 39 |
vars_files: |
| 40 |
- vars/server.yml |
| 41 |
- vars/hostgroup.yml |
| 42 |
tasks: |
| 43 |
- name: create HG |
| 44 |
include_tasks: tasks/hostgroup.yml |
| 45 |
vars: |
| 46 |
hostgroup_name: "New host group" |
| 47 |
hostgroup_locations: "{{ hostgroup.locations }}" |
| 48 |
hostgroup_organizations: "{{ hostgroup.organizations }}" |
| 49 |
hostgroup_organization: "{{ hostgroup.organizations | first }}" |
| 50 |
hostgroup_content_source: "{{ hostgroup.content_source }}" |
| 51 |
hostgroup_lifecycle_environment: "{{ hostgroup.lifecycle_environment }}" |
| 52 |
hostgroup_content_view: "{{ hostgroup.content_view.name }}" |
| 53 |
hostgroup_parameters: |
| 54 |
- name: test_param_one |
| 55 |
parameter_type: string |
| 56 |
value: oneoneone |
| 57 |
hostgroup_activation_keys: key_one |
| 58 |
hostgroup_state: present |
| 59 |
expected_change: true |
| 60 |
|
| 61 |
- name: create HG again, no change |
| 62 |
include_tasks: tasks/hostgroup.yml |
| 63 |
vars: |
| 64 |
hostgroup_name: "New host group" |
| 65 |
hostgroup_locations: "{{ hostgroup.locations }}" |
| 66 |
hostgroup_organizations: "{{ hostgroup.organizations }}" |
| 67 |
hostgroup_organization: "{{ hostgroup.organizations | first }}" |
| 68 |
hostgroup_content_source: "{{ hostgroup.content_source }}" |
| 69 |
hostgroup_lifecycle_environment: "{{ hostgroup.lifecycle_environment }}" |
| 70 |
hostgroup_content_view: "{{ hostgroup.content_view.name }}" |
| 71 |
hostgroup_parameters: |
| 72 |
- name: test_param_one |
| 73 |
parameter_type: string |
| 74 |
value: oneoneone |
| 75 |
hostgroup_activation_keys: key_one |
| 76 |
hostgroup_state: present |
| 77 |
expected_change: false |
| 78 |
|
| 79 |
- name: only set AK, HG should not lose params, no change |
| 80 |
include_tasks: tasks/hostgroup.yml |
| 81 |
vars: |
| 82 |
hostgroup_name: "New host group" |
| 83 |
hostgroup_organizations: "{{ hostgroup.organizations }}" |
| 84 |
hostgroup_organization: "{{ hostgroup.organizations | first }}" |
| 85 |
hostgroup_activation_keys: key_one |
| 86 |
hostgroup_state: present |
| 87 |
expected_change: false |
| 88 |
|
| 89 |
- name: only set params, HG should not lose AK, no change |
| 90 |
include_tasks: tasks/hostgroup.yml |
| 91 |
vars: |
| 92 |
hostgroup_name: "New host group" |
| 93 |
hostgroup_organizations: "{{ hostgroup.organizations }}" |
| 94 |
hostgroup_organization: "{{ hostgroup.organizations | first }}" |
| 95 |
hostgroup_parameters: |
| 96 |
- name: test_param_one |
| 97 |
parameter_type: string |
| 98 |
value: oneoneone |
| 99 |
hostgroup_state: present |
| 100 |
expected_change: false |
| 101 |
|
| 102 |
- name: only set AK via params |
| 103 |
include_tasks: tasks/hostgroup.yml |
| 104 |
vars: |
| 105 |
hostgroup_name: "New host group" |
| 106 |
hostgroup_organizations: "{{ hostgroup.organizations }}" |
| 107 |
hostgroup_organization: "{{ hostgroup.organizations | first }}" |
| 108 |
hostgroup_parameters: |
| 109 |
- name: kt_activation_keys |
| 110 |
parameter_type: string |
| 111 |
value: new_key |
| 112 |
hostgroup_state: present |
| 113 |
expected_change: true |
| 114 |
|
| 115 |
- name: only set AK via params, again, no change |
| 116 |
include_tasks: tasks/hostgroup.yml |
| 117 |
vars: |
| 118 |
hostgroup_name: "New host group" |
| 119 |
hostgroup_organizations: "{{ hostgroup.organizations }}" |
| 120 |
hostgroup_organization: "{{ hostgroup.organizations | first }}" |
| 121 |
hostgroup_parameters: |
| 122 |
- name: kt_activation_keys |
| 123 |
parameter_type: string |
| 124 |
value: new_key |
| 125 |
hostgroup_state: present |
| 126 |
expected_change: false |
| 127 |
|
| 128 |
- name: delete HG |
| 129 |
include_tasks: tasks/hostgroup.yml |
| 130 |
vars: |
| 131 |
hostgroup_name: "New host group" |
| 132 |
hostgroup_state: absent |
| 133 |
expected_change: true |
| 134 |
|
| 135 |
- name: delete HG again, no change |
| 136 |
include_tasks: tasks/hostgroup.yml |
| 137 |
vars: |
| 138 |
hostgroup_name: "New host group" |
| 139 |
hostgroup_state: absent |
| 140 |
expected_change: false |
| 141 |
|
| 142 |
- hosts: localhost |
| 143 |
collections: |
| 144 |
- theforeman.foreman |
| 145 |
gather_facts: false |
| 146 |
vars_files: |
| 147 |
- vars/server.yml |
| 148 |
- vars/hostgroup.yml |
| 149 |
tasks: |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
- include_tasks: tasks/location.yml |
| 164 |
vars: |
| 165 |
location_name: "{{ item }}" |
| 166 |
location_state: "absent" |
| 167 |
with_items: "{{ hostgroup.locations | reverse | list }}" |
| 168 |
- include_tasks: tasks/organization.yml |
| 169 |
vars: |
| 170 |
organization_name: "{{ item }}" |
| 171 |
organization_state: "absent" |
| 172 |
|
| 173 |
|
| 174 |
with_items: "{{ hostgroup.organizations | difference([hostgroup.organizations | first]) }}" |
| 175 |
... |