forked from theforeman/foreman-ansible-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
151 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |