Let's get this party started
This commit is contained in:
parent
b90a0f9e27
commit
525fdfc1cd
|
@ -0,0 +1,4 @@
|
||||||
|
schema: {}
|
||||||
|
hieradata: {}
|
||||||
|
hieradata_file: ''
|
||||||
|
fact_variable: ''
|
|
@ -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,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 != ''
|
|
@ -0,0 +1,2 @@
|
||||||
|
ansible
|
||||||
|
flake8
|
|
@ -0,0 +1,3 @@
|
||||||
|
[defaults]
|
||||||
|
roles_path=../..
|
||||||
|
nocows=1
|
|
@ -0,0 +1 @@
|
||||||
|
localhost
|
|
@ -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
|
|
@ -0,0 +1 @@
|
||||||
|
localhost
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
connection: local
|
||||||
|
remote_user: root
|
||||||
|
roles:
|
||||||
|
- role: ansible-role-k8s-tripleo
|
||||||
|
- role: parse-tripleo-hiera
|
|
@ -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
|
Loading…
Reference in New Issue