Let's get this party started

This commit is contained in:
Flavio Percoco 2017-07-13 13:18:13 +02:00
parent b90a0f9e27
commit 525fdfc1cd
11 changed files with 194 additions and 0 deletions

4
defaults/main.yml Normal file
View File

@ -0,0 +1,4 @@
schema: {}
hieradata: {}
hieradata_file: ''
fact_variable: ''

View File

@ -0,0 +1,101 @@
#!/usr/bin/env python
DOCUMENTATION = '''
---
module: helm
short_description: Manages Kubernetes packages with the Helm package manager
version_added: "2.4"
author: "Flavio Percoco (flaper87)"
description:
- Install, upgrade, delete and list packages with the Helm package manage
requirements:
- "pyhelm"
- "grpcio"
options:
host:
description:
- Tiller's server host
required: false
default: "localhost"
port:
description:
- Tiller's server port
required: false
default: 44134
namespace:
description:
- Kubernetes namespace where the chart should be installed
required: false
default: "default"
name:
description:
- Release name to manage
required: false
default: null
'''
RETURN = ''' # '''
EXAMPLES = '''
- name: Install helm chart
helm:
host: localhost
chart:
name: memcached
version: 0.4.0
source:
type: repo
location: https://kubernetes-charts.storage.googleapis.com
state: installed
name: my-memcached
namespace: default
- name: Uninstall helm chart
helm:
host: localhost
state: absent
name: my-memcached
'''
import os
import yaml
from ansible.module_utils.basic import AnsibleModule
def main():
"""The main function."""
module = AnsibleModule(
argument_spec=dict(
hieradata=dict(type='dict', default={}),
hieradata_file=dict(type='str', default=''),
schema=dict(type='dict'),
),
supports_check_mode=True)
schema = module.params['schema']
hieradata = module.params['hieradata']
hieradata_file = module.params['hieradata_file']
if not (hieradata or hieradata_file):
module.fail_json(msg="Either hieradata or hieradata_file must be set")
if os.path.exists(hieradata_file):
hieradata = yaml.safe_load(hieradata_file)
conf_dict = {}
for key, mapping in schema.items():
if not key in hieradata:
continue
value = hieradata[key]
group, name = mapping.split('.')
conf_dict.setdefault(group, {})[name] = value
module.exit_json(**{'conf_dict': conf_dict})
if __name__ == '__main__':
main()

0
requirements.txt Normal file
View File

14
tasks/main.yml Normal file
View File

@ -0,0 +1,14 @@
- name: Translate hieradata
parse_tripleo_hiera:
hieradata: '{{ hieradata }}'
schema: '{{ schema }}'
when:
- hieradata or hieradata_file
- schema
register: result
- name: Set facts
set_fact:
'{{fact_variable}}': '{{result.conf_dict}}'
when:
- fact_variable != ''

2
test-requirements.txt Normal file
View File

@ -0,0 +1,2 @@
ansible
flake8

3
tests/ansible.cfg Normal file
View File

@ -0,0 +1,3 @@
[defaults]
roles_path=../..
nocows=1

1
tests/inventory Normal file
View File

@ -0,0 +1 @@
localhost

View File

@ -0,0 +1,33 @@
- name: Test hieradata
parse_tripleo_hiera:
hieradata:
glance::api::v1: True
schema:
glance::api::v1: DEFAULT.enable_glance_v1
register: result
- name: Check values
fail:
msg: "DEFAULT not in conf_dict"
when:
- not result.conf_dict['DEFAULT']
- not result.conf_dict['DEFAULT']['enable_glance_v1']
- name: Test include role
include_role:
name: 'ansible-role-k8s-tripleo'
vars:
hieradata:
glance::api::v1: True
schema:
glance::api::v1: DEFAULT.enable_glance_v1
fact_variable: 'glance_config'
- name: Check fact glance_config
fail:
msg: "glance_config not set"
when:
- not glance_config

1
tests/test.retry Normal file
View File

@ -0,0 +1 @@
localhost

7
tests/test.yml Normal file
View File

@ -0,0 +1,7 @@
---
- hosts: localhost
connection: local
remote_user: root
roles:
- role: ansible-role-k8s-tripleo
- role: parse-tripleo-hiera

28
tox.ini Normal file
View File

@ -0,0 +1,28 @@
[tox]
minversion = 1.6
envlist = py27,pep8
skipsdist = True
[testenv]
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
whitelist_externals = find
[testenv:pep8]
commands = flake8
[testenv:venv]
# NOTE(jaegerandi): this target does not use constraints because
# upstream infra does not yet support it. Once that's fixed, we can
# drop the install_command.
install_command = pip install -U --force-reinstall {opts} {packages}
changedir={toxinidir}/tests
commands =
find . -type f -name "*.pyc" -delete
ansible-playbook -i inventory test.yml
[flake8]
exclude = .venv*,.git,.tox,dist,doc,*lib/python*,*.egg,.update-venv
max-complexity = 16