From e43340739f220a6395964c673eebba35df4b14fd Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Tue, 22 Dec 2020 15:04:33 +0000 Subject: [PATCH] Add role for managing hostgroups --- changelogs/fragments/1116-hostgroups-role.yml | 2 + roles/hostgroups/README.md | 75 ++++++ roles/hostgroups/tasks/main.yml | 42 +++ tests/fixtures/apidoc/hostgroups_role.json | 1 + .../fixtures/hostgroups_role-0.yml | 176 ++++++++++++ .../fixtures/hostgroups_role-1.yml | 252 ++++++++++++++++++ .../fixtures/hostgroups_role-2.yml | 236 ++++++++++++++++ tests/test_playbooks/hostgroups_role.yml | 29 ++ 8 files changed, 813 insertions(+) create mode 100644 changelogs/fragments/1116-hostgroups-role.yml create mode 100644 roles/hostgroups/README.md create mode 100644 roles/hostgroups/tasks/main.yml create mode 120000 tests/fixtures/apidoc/hostgroups_role.json create mode 100644 tests/test_playbooks/fixtures/hostgroups_role-0.yml create mode 100644 tests/test_playbooks/fixtures/hostgroups_role-1.yml create mode 100644 tests/test_playbooks/fixtures/hostgroups_role-2.yml create mode 100644 tests/test_playbooks/hostgroups_role.yml diff --git a/changelogs/fragments/1116-hostgroups-role.yml b/changelogs/fragments/1116-hostgroups-role.yml new file mode 100644 index 0000000000..7203e01af4 --- /dev/null +++ b/changelogs/fragments/1116-hostgroups-role.yml @@ -0,0 +1,2 @@ +minor_changes: + - Add a hostgroups role (https://github.com/theforeman/foreman-ansible-modules/issues/1116) diff --git a/roles/hostgroups/README.md b/roles/hostgroups/README.md new file mode 100644 index 0000000000..3b1af61161 --- /dev/null +++ b/roles/hostgroups/README.md @@ -0,0 +1,75 @@ +theforeman.foreman.hostgroups +============================= + +This role creates and manages Hostgroups. + +Role Variables +-------------- + +This role supports the [Common Role Variables](https://github.com/theforeman/foreman-ansible-modules/blob/develop/README.md#common-role-variables). + +- `foreman_hostgroups`: List of hostgroups to manage that are each represented as a dictionary. See module documentation for a list of available options for each hostgroup. + Hostgroups may have any set of fields defined on them and may optionally define a `parent` for nested hostgroups. + A variety of examples are demonstrated in the data structure below: + +```yaml +foreman_hostgroups: + - name: "Basic example" + architecture: "x86_64" + operatingsystem: "CentOS" + medium: "media_name" + ptable: "partition_table_name" + - name: "Proxies hostgroup" + environment: production + puppet_proxy: puppet-proxy.example.com + puppet_ca_proxy: puppet-proxy.example.com + openscap_proxy: openscap-proxy.example.com + - name: "CentOS 7" + organization: "Default Organization" + lifecycle_environment: "Production" + content_view: "CentOS 7" + activation_keys: centos-7 + - name: "Webserver" + parent: "CentOS 7" + environment: production + puppet_proxy: puppet-proxy.example.com + puppet_ca_proxy: puppet-proxy.example.com + openscap_proxy: openscap-proxy.example.com +``` + +Example Playbooks +----------------- + +This example creates several hostgroups with some nested examples. + +```yaml +- hosts: localhost + roles: + - role: theforeman.foreman.hostgroups + vars: + foreman_server_url: https://foreman.example.com + foreman_username: "admin" + foreman_password: "changeme" + foreman_hostgroups: + - name: "Basic example" + architecture: "x86_64" + operatingsystem: "CentOS" + medium: "media_name" + ptable: "partition_table_name" + - name: "Proxies hostgroup" + environment: production + puppet_proxy: puppet-proxy.example.com + puppet_ca_proxy: puppet-proxy.example.com + openscap_proxy: openscap-proxy.example.com + - name: "CentOS 7" + organization: "Default Organization" + lifecycle_environment: "Production" + content_view: "CentOS 7" + activation_keys: centos-7 + - name: "Webserver" + parent: "CentOS 7" + environment: production + puppet_proxy: puppet-proxy.example.com + puppet_ca_proxy: puppet-proxy.example.com + openscap_proxy: openscap-proxy.example.com +``` diff --git a/roles/hostgroups/tasks/main.yml b/roles/hostgroups/tasks/main.yml new file mode 100644 index 0000000000..55d60d056b --- /dev/null +++ b/roles/hostgroups/tasks/main.yml @@ -0,0 +1,42 @@ +--- +- name: 'Create Hostgroups' + theforeman.foreman.hostgroup: + username: "{{ foreman_username | default(omit) }}" + password: "{{ foreman_password | default(omit) }}" + server_url: "{{ foreman_server_url | default(omit) }}" + validate_certs: "{{ validate_certs | default(omit) }}" + name: "{{ item.name }}" + updated_name: "{{ item.updated_name | default(omit) }}" + description: "{{ item.description | default(omit) }}" + parent: "{{ item.parent | default(omit) }}" + organization: "{{ item.organization | default(omit) }}" + organizations: "{{ item.organizations | default(omit) }}" + locations: "{{ item.locations | default(omit) }}" + architecture: "{{ item.architecture | default(omit) }}" + operatingsystem: "{{ item.operatingsystem | default(omit) }}" + medium: "{{ item.medium | default(omit) }}" + ptable: "{{ item.ptable | default(omit) }}" + parameters: "{{ item.parameters | default(omit) }}" + ansible_roles: "{{ item.ansible_roles | default(omit) }}" + compute_resource: "{{ item.compute_resource | default(omit) }}" + compute_profile: "{{ item.compute_profile | default(omit) }}" + domain: "{{ item.domain | default(omit) }}" + subnet: "{{ item.subnet | default(omit) }}" + subnet6: "{{ item.subnet6 | default(omit) }}" + root_pass: "{{ item.root_pass | default(omit) }}" + realm: "{{ item.realm | default(omit) }}" + pxe_loader: "{{ item.pxe_loader | default(omit) }}" + environment: "{{ item.environment | default(omit) }}" + puppetclasses: "{{ item.puppetclasses | default(omit) }}" + config_groups: "{{ item.config_groups | default(omit) }}" + puppet_proxy: "{{ item.puppet_proxy | default(omit) }}" + puppet_ca_proxy: "{{ item.puppet_ca_proxy | default(omit) }}" + openscap_proxy: "{{ item.openscap_proxy | default(omit) }}" + content_source: "{{ item.content_source | default(omit) }}" + lifecycle_environment: "{{ item.lifecycle_environment | default(omit) }}" + kickstart_repository: "{{ item.kickstart_repository | default(omit) }}" + content_view: "{{ item.content_view | default(omit) }}" + activation_keys: "{{ item.activation_keys | default(omit) }}" + state: "{{ item.state | default(omit) }}" + with_items: + - "{{ foreman_hostgroups }}" diff --git a/tests/fixtures/apidoc/hostgroups_role.json b/tests/fixtures/apidoc/hostgroups_role.json new file mode 120000 index 0000000000..f9e401512c --- /dev/null +++ b/tests/fixtures/apidoc/hostgroups_role.json @@ -0,0 +1 @@ +foreman.json \ No newline at end of file diff --git a/tests/test_playbooks/fixtures/hostgroups_role-0.yml b/tests/test_playbooks/fixtures/hostgroups_role-0.yml new file mode 100644 index 0000000000..b83fa367c2 --- /dev/null +++ b/tests/test_playbooks/fixtures/hostgroups_role-0.yml @@ -0,0 +1,176 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: GET + uri: https://foreman.example.org/api/status + response: + body: + string: '{"result":"ok","status":200,"version":"2.4.0-develop","api_version":2}' + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=100 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + content-length: + - '70' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: GET + uri: https://foreman.example.org/api/hostgroups?search=title%3D%22Hostgroup1%22&per_page=4294967296 + response: + body: + string: "{\n \"total\": 0,\n \"subtotal\": 0,\n \"page\": 1,\n \"per_page\"\ + : 4294967296,\n \"search\": \"title=\\\"Hostgroup1\\\"\",\n \"sort\": {\n\ + \ \"by\": null,\n \"order\": null\n },\n \"results\": []\n}\n" + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=99 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + content-length: + - '177' + status: + code: 200 + message: OK +- request: + body: '{"hostgroup": {"name": "Hostgroup1"}}' + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '37' + Content-Type: + - application/json + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: POST + uri: https://foreman.example.org/api/hostgroups + response: + body: + string: '{"subnet_id":null,"subnet_name":null,"operatingsystem_id":null,"operatingsystem_name":null,"domain_id":null,"domain_name":null,"environment_id":null,"environment_name":null,"compute_profile_id":null,"compute_profile_name":null,"ancestry":null,"parent_id":null,"parent_name":null,"ptable_id":null,"ptable_name":null,"medium_id":null,"medium_name":null,"pxe_loader":null,"subnet6_id":null,"subnet6_name":null,"compute_resource_id":null,"compute_resource_name":null,"architecture_id":null,"architecture_name":null,"realm_id":null,"realm_name":null,"created_at":"2020-12-22 + 15:01:20 UTC","updated_at":"2020-12-22 15:01:20 UTC","id":1,"name":"Hostgroup1","title":"Hostgroup1","description":null,"puppet_proxy_id":null,"puppet_proxy_name":null,"puppet_ca_proxy_id":null,"puppet_ca_proxy_name":null,"puppet_proxy":null,"puppet_ca_proxy":null,"inherited_compute_profile_id":null,"inherited_environment_id":null,"inherited_domain_id":null,"inherited_puppet_proxy_id":null,"inherited_puppet_ca_proxy_id":null,"inherited_compute_resource_id":null,"inherited_operatingsystem_id":null,"inherited_architecture_id":null,"inherited_medium_id":null,"inherited_ptable_id":null,"inherited_subnet_id":null,"inherited_subnet6_id":null,"inherited_realm_id":null,"inherited_pxe_loader":null,"parameters":[],"template_combinations":[],"puppetclasses":[],"config_groups":[],"all_puppetclasses":[],"locations":[{"id":2,"name":"Default + Location","title":"Default Location","description":null}],"organizations":[]}' + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=98 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Transfer-Encoding: + - chunked + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + status: + code: 201 + message: Created +version: 1 diff --git a/tests/test_playbooks/fixtures/hostgroups_role-1.yml b/tests/test_playbooks/fixtures/hostgroups_role-1.yml new file mode 100644 index 0000000000..0231d7b355 --- /dev/null +++ b/tests/test_playbooks/fixtures/hostgroups_role-1.yml @@ -0,0 +1,252 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: GET + uri: https://foreman.example.org/api/status + response: + body: + string: '{"result":"ok","status":200,"version":"2.4.0-develop","api_version":2}' + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=100 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + content-length: + - '70' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: GET + uri: https://foreman.example.org/api/hostgroups?search=title%3D%22Hostgroup1%2FHostgroup2%22&per_page=4294967296 + response: + body: + string: "{\n \"total\": 1,\n \"subtotal\": 0,\n \"page\": 1,\n \"per_page\"\ + : 4294967296,\n \"search\": \"title=\\\"Hostgroup1/Hostgroup2\\\"\",\n \"\ + sort\": {\n \"by\": null,\n \"order\": null\n },\n \"results\": []\n\ + }\n" + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=99 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + content-length: + - '188' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: GET + uri: https://foreman.example.org/api/hostgroups?search=title%3D%22Hostgroup1%22&per_page=4294967296 + response: + body: + string: "{\n \"total\": 1,\n \"subtotal\": 1,\n \"page\": 1,\n \"per_page\"\ + : 4294967296,\n \"search\": \"title=\\\"Hostgroup1\\\"\",\n \"sort\": {\n\ + \ \"by\": null,\n \"order\": null\n },\n \"results\": [{\"subnet_id\"\ + :null,\"subnet_name\":null,\"operatingsystem_id\":null,\"operatingsystem_name\"\ + :null,\"domain_id\":null,\"domain_name\":null,\"environment_id\":null,\"environment_name\"\ + :null,\"compute_profile_id\":null,\"compute_profile_name\":null,\"ancestry\"\ + :null,\"parent_id\":null,\"parent_name\":null,\"ptable_id\":null,\"ptable_name\"\ + :null,\"medium_id\":null,\"medium_name\":null,\"pxe_loader\":null,\"subnet6_id\"\ + :null,\"subnet6_name\":null,\"compute_resource_id\":null,\"compute_resource_name\"\ + :null,\"architecture_id\":null,\"architecture_name\":null,\"realm_id\":null,\"\ + realm_name\":null,\"created_at\":\"2020-12-22 15:01:20 UTC\",\"updated_at\"\ + :\"2020-12-22 15:01:20 UTC\",\"id\":1,\"name\":\"Hostgroup1\",\"title\":\"\ + Hostgroup1\",\"description\":null,\"puppet_proxy_id\":null,\"puppet_proxy_name\"\ + :null,\"puppet_ca_proxy_id\":null,\"puppet_ca_proxy_name\":null,\"puppet_proxy\"\ + :null,\"puppet_ca_proxy\":null,\"inherited_compute_profile_id\":null,\"inherited_environment_id\"\ + :null,\"inherited_domain_id\":null,\"inherited_puppet_proxy_id\":null,\"inherited_puppet_ca_proxy_id\"\ + :null,\"inherited_compute_resource_id\":null,\"inherited_operatingsystem_id\"\ + :null,\"inherited_architecture_id\":null,\"inherited_medium_id\":null,\"inherited_ptable_id\"\ + :null,\"inherited_subnet_id\":null,\"inherited_subnet6_id\":null,\"inherited_realm_id\"\ + :null,\"inherited_pxe_loader\":null}]\n}\n" + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=98 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + content-length: + - '1445' + status: + code: 200 + message: OK +- request: + body: '{"hostgroup": {"name": "Hostgroup2", "parent_id": 1}}' + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '53' + Content-Type: + - application/json + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: POST + uri: https://foreman.example.org/api/hostgroups + response: + body: + string: '{"subnet_id":null,"subnet_name":null,"operatingsystem_id":null,"operatingsystem_name":null,"domain_id":null,"domain_name":null,"environment_id":null,"environment_name":null,"compute_profile_id":null,"compute_profile_name":null,"ancestry":"1","parent_id":1,"parent_name":"Hostgroup1","ptable_id":null,"ptable_name":null,"medium_id":null,"medium_name":null,"pxe_loader":null,"subnet6_id":null,"subnet6_name":null,"compute_resource_id":null,"compute_resource_name":null,"architecture_id":null,"architecture_name":null,"realm_id":null,"realm_name":null,"created_at":"2020-12-22 + 15:01:21 UTC","updated_at":"2020-12-22 15:01:21 UTC","id":2,"name":"Hostgroup2","title":"Hostgroup1/Hostgroup2","description":null,"puppet_proxy_id":null,"puppet_proxy_name":null,"puppet_ca_proxy_id":null,"puppet_ca_proxy_name":null,"puppet_proxy":null,"puppet_ca_proxy":null,"inherited_compute_profile_id":null,"inherited_environment_id":null,"inherited_domain_id":null,"inherited_puppet_proxy_id":null,"inherited_puppet_ca_proxy_id":null,"inherited_compute_resource_id":null,"inherited_operatingsystem_id":null,"inherited_architecture_id":null,"inherited_medium_id":null,"inherited_ptable_id":null,"inherited_subnet_id":null,"inherited_subnet6_id":null,"inherited_realm_id":null,"inherited_pxe_loader":null,"parameters":[],"template_combinations":[],"puppetclasses":[],"config_groups":[],"all_puppetclasses":[],"locations":[{"id":2,"name":"Default + Location","title":"Default Location","description":null}],"organizations":[]}' + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=97 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Transfer-Encoding: + - chunked + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + status: + code: 201 + message: Created +version: 1 diff --git a/tests/test_playbooks/fixtures/hostgroups_role-2.yml b/tests/test_playbooks/fixtures/hostgroups_role-2.yml new file mode 100644 index 0000000000..77a6d5552f --- /dev/null +++ b/tests/test_playbooks/fixtures/hostgroups_role-2.yml @@ -0,0 +1,236 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: GET + uri: https://foreman.example.org/api/status + response: + body: + string: '{"result":"ok","status":200,"version":"2.4.0-develop","api_version":2}' + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=100 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + content-length: + - '70' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: GET + uri: https://foreman.example.org/api/hostgroups?search=title%3D%22Hostgroup3%22&per_page=4294967296 + response: + body: + string: "{\n \"total\": 2,\n \"subtotal\": 0,\n \"page\": 1,\n \"per_page\"\ + : 4294967296,\n \"search\": \"title=\\\"Hostgroup3\\\"\",\n \"sort\": {\n\ + \ \"by\": null,\n \"order\": null\n },\n \"results\": []\n}\n" + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=99 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + content-length: + - '177' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: GET + uri: https://foreman.example.org/api/architectures?search=name%3D%22x86_64%22&per_page=4294967296 + response: + body: + string: "{\n \"total\": 2,\n \"subtotal\": 1,\n \"page\": 1,\n \"per_page\"\ + : 4294967296,\n \"search\": \"name=\\\"x86_64\\\"\",\n \"sort\": {\n \ + \ \"by\": null,\n \"order\": null\n },\n \"results\": [{\"created_at\"\ + :\"2020-12-10 17:44:07 UTC\",\"updated_at\":\"2020-12-10 17:44:07 UTC\",\"\ + name\":\"x86_64\",\"id\":1}]\n}\n" + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=98 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + content-length: + - '274' + status: + code: 200 + message: OK +- request: + body: '{"hostgroup": {"name": "Hostgroup3", "architecture_id": 1}}' + headers: + Accept: + - application/json;version=2 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '59' + Content-Type: + - application/json + User-Agent: + - apypie (https://github.com/Apipie/apypie) + method: POST + uri: https://foreman.example.org/api/hostgroups + response: + body: + string: '{"subnet_id":null,"subnet_name":null,"operatingsystem_id":null,"operatingsystem_name":null,"domain_id":null,"domain_name":null,"environment_id":null,"environment_name":null,"compute_profile_id":null,"compute_profile_name":null,"ancestry":null,"parent_id":null,"parent_name":null,"ptable_id":null,"ptable_name":null,"medium_id":null,"medium_name":null,"pxe_loader":null,"subnet6_id":null,"subnet6_name":null,"compute_resource_id":null,"compute_resource_name":null,"architecture_id":1,"architecture_name":"x86_64","realm_id":null,"realm_name":null,"created_at":"2020-12-22 + 15:01:22 UTC","updated_at":"2020-12-22 15:01:22 UTC","id":3,"name":"Hostgroup3","title":"Hostgroup3","description":null,"puppet_proxy_id":null,"puppet_proxy_name":null,"puppet_ca_proxy_id":null,"puppet_ca_proxy_name":null,"puppet_proxy":null,"puppet_ca_proxy":null,"inherited_compute_profile_id":null,"inherited_environment_id":null,"inherited_domain_id":null,"inherited_puppet_proxy_id":null,"inherited_puppet_ca_proxy_id":null,"inherited_compute_resource_id":null,"inherited_operatingsystem_id":null,"inherited_architecture_id":null,"inherited_medium_id":null,"inherited_ptable_id":null,"inherited_subnet_id":null,"inherited_subnet6_id":null,"inherited_realm_id":null,"inherited_pxe_loader":null,"parameters":[],"template_combinations":[],"puppetclasses":[],"config_groups":[],"all_puppetclasses":[],"locations":[{"id":2,"name":"Default + Location","title":"Default Location","description":null}],"organizations":[]}' + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Connection: + - Keep-Alive + Content-Security-Policy: + - 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:; + img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self''; + style-src ''unsafe-inline'' ''self''' + Content-Type: + - application/json; charset=utf-8 + Foreman_api_version: + - '2' + Foreman_current_location: + - ; ANY + Foreman_current_organization: + - ; ANY + Foreman_version: + - 2.4.0-develop + Keep-Alive: + - timeout=15, max=97 + Strict-Transport-Security: + - max-age=631139040; includeSubdomains + Transfer-Encoding: + - chunked + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - sameorigin + X-Permitted-Cross-Domain-Policies: + - none + X-XSS-Protection: + - 1; mode=block + status: + code: 201 + message: Created +version: 1 diff --git a/tests/test_playbooks/hostgroups_role.yml b/tests/test_playbooks/hostgroups_role.yml new file mode 100644 index 0000000000..5b45b4e01c --- /dev/null +++ b/tests/test_playbooks/hostgroups_role.yml @@ -0,0 +1,29 @@ +--- +- hosts: localhost + collections: + - theforeman.foreman + gather_facts: false + vars_files: + - vars/server.yml + tasks: + - name: ensure test organization + include_tasks: tasks/organization.yml + vars: + organization_name: "Test Organization" + organization_state: "present" + +- hosts: tests + collections: + - theforeman.foreman + gather_facts: false + vars_files: + - vars/server.yml + roles: + - role: hostgroups + vars: + foreman_hostgroups: + - name: Hostgroup1 + - name: Hostgroup2 + parent: Hostgroup1 + - name: Hostgroup3 + architecture: "x86_64"