Skip to content

Commit

Permalink
move tasks into a tasks file
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Oct 9, 2020
1 parent bc92373 commit fe0f1d0
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 149 deletions.
150 changes: 1 addition & 149 deletions tests/test_playbooks/inventory_plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
150 changes: 150 additions & 0 deletions tests/test_playbooks/tasks/inventory_plugin.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fe0f1d0

Please sign in to comment.