From fe0f1d0d6f1ccd5cf2d00ff0794c7f5b940a6a32 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Fri, 9 Oct 2020 13:42:33 +0200 Subject: [PATCH] move tasks into a tasks file --- tests/test_playbooks/inventory_plugin.yml | 150 +----------------- .../test_playbooks/tasks/inventory_plugin.yml | 150 ++++++++++++++++++ 2 files changed, 151 insertions(+), 149 deletions(-) create mode 100644 tests/test_playbooks/tasks/inventory_plugin.yml diff --git a/tests/test_playbooks/inventory_plugin.yml b/tests/test_playbooks/inventory_plugin.yml index 6fe1ed0ef1..079d589c55 100644 --- a/tests/test_playbooks/inventory_plugin.yml +++ b/tests/test_playbooks/inventory_plugin.yml @@ -20,152 +20,4 @@ - community.general - theforeman.foreman tasks: - - name: fetch PostgreSQL container - docker_image: - name: postgres:{{ _postgres_version }} - source: pull - - - name: fetch Foreman container - docker_image: - name: "{{ _foreman_container }}:{{ _foreman_version }}" - source: pull - - - name: start PostgreSQL container - docker_container: - name: "{{ _postgres_host }}" - image: postgres:{{ _postgres_version }} - env: - POSTGRES_USER: foreman - POSTGRES_PASSWORD: foreman - POSTGRES_DATABASE: foreman - PGDATA: /var/lib/postgresql/data/pgdata - published_ports: - - "0.0.0.0:5432:5432" - - - name: start Foreman container - docker_container: - name: "{{ _foreman_host }}" - image: "{{ _foreman_container }}:{{ _foreman_version }}" - command: bash -c "bundle exec bin/rails db:create db:migrate && bundle exec bin/rails db:seed && bundle exec bin/rails server -b 0.0.0.0" - env: - SEED_ADMIN_PASSWORD: changeme - RAILS_ENV: production - DATABASE_URL: postgres://foreman:foreman@{{ _postgres_host }}/foreman?pool=5 - links: - - "{{ _postgres_host }}:{{ _postgres_host }}" - published_ports: - - "0.0.0.0:{{ _foreman_port }}:3000" - - - name: wait for foreman to start - status_info: - username: admin - password: changeme - server_url: http://127.0.0.1:{{ _foreman_port }}/ - register: result - until: - - result is success - - result.status.status == 200 - retries: 10 - delay: 10 - - - name: create test hostgroups - hostgroup: - username: admin - password: changeme - server_url: http://127.0.0.1:{{ _foreman_port }}/ - name: "{{ item.name }}" - parent: "{{ item.parent | default(omit) }}" - organizations: - - Default Organization - locations: - - Default Location - with_items: "{{ foreman_groups }}" - - - name: create test hosts - host: - username: admin - password: changeme - server_url: http://127.0.0.1:{{ _foreman_port }}/ - name: "{{ item.key }}" - hostgroup: "{{ item.value }}" - build: false - organization: Default Organization - location: Default Location - managed: false - parameters: - - name: testparam1 - value: testvalue1 - - name: testparam2 - value: testvalue2 - with_dict: "{{ foreman_hosts }}" - - - name: submit facts for hosts - uri: - url: http://127.0.0.1:{{ _foreman_port }}/api/hosts/facts - url_username: admin - url_password: changeme - validate_certs: false - method: POST - body: - name: "{{ item.key }}" - facts: - fqdn: "{{ item.key }}" - domain: example.com - famtesthost: true - operatingsystem: CentOS - operatingsystemrelease: "7.7" - force_basic_auth: true - status_code: 201 - body_format: json - with_dict: "{{ foreman_hosts }}" - ignore_errors: true - - - name: Refresh inventory to ensure new instances exist in inventory - meta: refresh_inventory - - - name: test that all groups are present - assert: - that: > - 'foreman_{{ item.label | default(item.name) | regex_replace('/', '_') }}' in groups - with_items: "{{ foreman_groups }}" - - - name: test that all hosts are in the "all" group - assert: - that: > - '{{ item.key }}' in groups['all'] - with_dict: "{{ foreman_hosts }}" - - - name: test that all hosts are in the correct hostgroup - assert: - that: > - '{{ item.key }}' in groups['foreman_{{ item.value | regex_replace('/', '_') }}'] - with_dict: "{{ foreman_hosts }}" - - - name: test that all hosts have the domain fact set - assert: - that: > - hostvars['{{ item.key }}']['foreman_domain_name'] == 'example.com' - with_dict: "{{ foreman_hosts }}" - - - name: test that all hosts have the OS fact set - assert: - that: > - hostvars['{{ item.key }}']['foreman_operatingsystem_name'] == 'CentOS 7.7' - with_dict: "{{ foreman_hosts }}" - - - name: test that all hosts have the testparam1 - assert: - that: > - hostvars['{{ item.key }}']['testparam1'] == 'testvalue1' - with_dict: "{{ foreman_hosts }}" - - - name: test that all hosts have the testparam2 - assert: - that: > - hostvars['{{ item.key }}']['testparam2'] == 'testvalue2' - with_dict: "{{ foreman_hosts }}" - - - name: remove Foreman container - docker_container: - name: "{{ _foreman_host }}" - state: absent + - include_tasks: tasks/inventory_plugin.yml diff --git a/tests/test_playbooks/tasks/inventory_plugin.yml b/tests/test_playbooks/tasks/inventory_plugin.yml new file mode 100644 index 0000000000..79888cf149 --- /dev/null +++ b/tests/test_playbooks/tasks/inventory_plugin.yml @@ -0,0 +1,150 @@ +--- +- name: fetch PostgreSQL container + docker_image: + name: postgres:{{ _postgres_version }} + source: pull + +- name: fetch Foreman container + docker_image: + name: "{{ _foreman_container }}:{{ _foreman_version }}" + source: pull + +- name: start PostgreSQL container + docker_container: + name: "{{ _postgres_host }}" + image: postgres:{{ _postgres_version }} + env: + POSTGRES_USER: foreman + POSTGRES_PASSWORD: foreman + POSTGRES_DATABASE: foreman + PGDATA: /var/lib/postgresql/data/pgdata + published_ports: + - "0.0.0.0:5432:5432" + +- name: start Foreman container + docker_container: + name: "{{ _foreman_host }}" + image: "{{ _foreman_container }}:{{ _foreman_version }}" + command: bash -c "bundle exec bin/rails db:create db:migrate && bundle exec bin/rails db:seed && bundle exec bin/rails server -b 0.0.0.0" + env: + SEED_ADMIN_PASSWORD: changeme + RAILS_ENV: production + DATABASE_URL: postgres://foreman:foreman@{{ _postgres_host }}/foreman?pool=5 + links: + - "{{ _postgres_host }}:{{ _postgres_host }}" + published_ports: + - "0.0.0.0:{{ _foreman_port }}:3000" + +- name: wait for foreman to start + status_info: + username: admin + password: changeme + server_url: http://127.0.0.1:{{ _foreman_port }}/ + register: result + until: + - result is success + - result.status.status == 200 + retries: 10 + delay: 10 + +- name: create test hostgroups + hostgroup: + username: admin + password: changeme + server_url: http://127.0.0.1:{{ _foreman_port }}/ + name: "{{ item.name }}" + parent: "{{ item.parent | default(omit) }}" + organizations: + - Default Organization + locations: + - Default Location + with_items: "{{ foreman_groups }}" + +- name: create test hosts + host: + username: admin + password: changeme + server_url: http://127.0.0.1:{{ _foreman_port }}/ + name: "{{ item.key }}" + hostgroup: "{{ item.value }}" + build: false + organization: Default Organization + location: Default Location + managed: false + parameters: + - name: testparam1 + value: testvalue1 + - name: testparam2 + value: testvalue2 + with_dict: "{{ foreman_hosts }}" + +- name: submit facts for hosts + uri: + url: http://127.0.0.1:{{ _foreman_port }}/api/hosts/facts + url_username: admin + url_password: changeme + validate_certs: false + method: POST + body: + name: "{{ item.key }}" + facts: + fqdn: "{{ item.key }}" + domain: example.com + famtesthost: true + operatingsystem: CentOS + operatingsystemrelease: "7.7" + force_basic_auth: true + status_code: 201 + body_format: json + with_dict: "{{ foreman_hosts }}" + ignore_errors: true + +- name: Refresh inventory to ensure new instances exist in inventory + meta: refresh_inventory + +- name: test that all groups are present + assert: + that: > + 'foreman_{{ item.label | default(item.name) | regex_replace('/', '_') }}' in groups + with_items: "{{ foreman_groups }}" + +- name: test that all hosts are in the "all" group + assert: + that: > + '{{ item.key }}' in groups['all'] + with_dict: "{{ foreman_hosts }}" + +- name: test that all hosts are in the correct hostgroup + assert: + that: > + '{{ item.key }}' in groups['foreman_{{ item.value | regex_replace('/', '_') }}'] + with_dict: "{{ foreman_hosts }}" + +- name: test that all hosts have the domain fact set + assert: + that: > + hostvars['{{ item.key }}']['foreman_domain_name'] == 'example.com' + with_dict: "{{ foreman_hosts }}" + +- name: test that all hosts have the OS fact set + assert: + that: > + hostvars['{{ item.key }}']['foreman_operatingsystem_name'] == 'CentOS 7.7' + with_dict: "{{ foreman_hosts }}" + +- name: test that all hosts have the testparam1 + assert: + that: > + hostvars['{{ item.key }}']['testparam1'] == 'testvalue1' + with_dict: "{{ foreman_hosts }}" + +- name: test that all hosts have the testparam2 + assert: + that: > + hostvars['{{ item.key }}']['testparam2'] == 'testvalue2' + with_dict: "{{ foreman_hosts }}" + +- name: remove Foreman container + docker_container: + name: "{{ _foreman_host }}" + state: absent