Commit 88e9b735 authored by Dan Thomson's avatar Dan Thomson

Merge branch '4-allow-user-package-specification' into 'master'

Resolve "Allow user package specification"

Closes #4

See merge request !2
parents 0c6c4fdf ef6f8830
Pipeline #15871 passed with stage
in 10 minutes and 2 seconds
.venv
*.retry
*.sw[po]
*.pyc
__pycache__
......@@ -11,7 +11,5 @@ include:
molecule:
stage: test
variables:
DOCKER_TLS_CERTDIR: ""
tags:
- docker-dind-runner
- docker-runner
---
- name: Converge
hosts: all
tasks:
- name: Install epel release for CentOS
package:
name: epel-release
state: present
- name: "Include nagios"
include_role:
name: "nagios"
vars:
nagios_packages:
- nagios
- nagios-plugins-dhcp
---
dependency:
name: galaxy
driver:
name: docker
lint: |
ansible-lint
yamllint .
platforms:
- name: molecule_nagios_centos7
image: docker.io/pycontribs/centos:7
pre_build_image: true
# - name: molecule_nagios_centos6
# image: docker.io/pycontribs/centos:6
# pre_build_image: true
provisioner:
name: ansible
verifier:
name: testinfra
"""Use testinfra to ensure that some of our "default" packages are missing due
to our reduction of the standard package listing in this test scenario."""
# molecule/custom_packages/tests/test_missing_packages.py
import os
import sys
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_custom_packages(host):
if host.system_info.distribution.lower() == 'centos':
assert host.package('nagios').is_installed
assert host.package('nagios-plugins-dhcp').is_installed
assert (not host.package('nagios-plugins-users').is_installed)
assert (not host.package('nagios-plugins-disk').is_installed)
---
# This is an example playbook to execute Ansible tests.
- name: Verify
hosts: all
tasks:
- name: Example assertion
assert:
that: true
......@@ -2,6 +2,11 @@
- name: Converge
hosts: all
tasks:
- name: Install epel release for CentOS
package:
name: epel-release
state: present
- name: "Include nagios"
include_role:
name: "nagios"
---
- name: Try TRIUMF EPEL release
package:
name: triumf-epel-release
state: installed
ignore_errors: true
register: triumf_epel
become: yes
- name: Make sure EPEL is installed if TRIUMF epel failed
package:
name: epel-release
state: installed
when: triumf_epel.failed
become: yes
- name: Install other package dependencies
package:
name: "{{ packages }}"
name: >
{{ (nagios_packages|length > 0) |
ternary(
nagios_packages,
lookup(
'vars',
'nagios_packages_' +
ansible_distribution|lower +
ansible_distribution_major_version|string
)
)
}}
state: installed
become: yes
---
- name: Load platform variables
include_vars: "{{ found }}"
include_vars: "{{ filename }}"
vars:
distribution:
vars_files:
files:
- "{{ role_path }}/vars/{{ ansible_distribution | lower }}/\
{{ ansible_distribution_major_version }}.yml"
- "{{ role_path }}/vars/{{ ansible_distribution | lower }}/\
main.yml"
- "{{ role_path }}/vars/{{ ansible_distribution | lower }}.yml"
- "{{ role_path }}/vars/{{ ansible_os_family | lower }}.yml"
- "{{ role_path }}/vars/{{ ansible_os_family | lower }}/\
main.yml"
- "{{ role_path }}/vars/main.yml"
found: "{{ lookup('first_found', distribution, errors='ignore') }}"
skip: true
tags:
- platform_vars
when:
- "found|length > 0"
loop: "{{ q('first_found', vars_files, errors='ignore') }}"
loop_control:
loop_var: filename
- name: Load platform dependencies
include_tasks: "{{ found }}"
vars:
distribution:
tasks:
files:
- "{{ role_path }}/tasks/dependencies/\
{{ ansible_distribution | lower }}/\
{{ ansible_distribution_major_version }}.yml"
- "{{ role_path }}/tasks/dependencies/\
{{ ansible_distribution | lower }}/main.yml"
- "{{ role_path }}/tasks/dependencies/\
{{ ansible_distribution | lower }}.yml"
{{ ansible_distribution | lower }}/\
main.yml"
- "{{ role_path }}/tasks/dependencies/\
{{ ansible_os_family | lower }}.yml"
found: "{{ lookup('first_found', distribution, errors='ignore') }}"
skip: true
tags:
- platform_dependencies
when:
- "found|length > 0"
- "{{ role_path }}/tasks/dependencies/main.yml"
include_tasks: "{{ filename }}"
loop: "{{ q('first_found', tasks, errors='ignore') }}"
loop_control:
loop_var: filename
- name: Create destdirs
file:
......
packages:
nagios_packages_centos7:
- nagios
- nagios-plugins-dhcp
- nagios-plugins-disk
......@@ -13,6 +13,7 @@ packages:
- nagios-plugins-procs
- nagios-plugins-rpc
- nagios-plugins-smtp
- nagios-plugins-snmp
- nagios-plugins-ssh
- nagios-plugins-tcp
- nagios-plugins-users
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment