tripleo_container_configs module
To replace the task that looks over kolla_config.yaml and creates the json files per item in the YAML, create a module that will lead to one task creating all the files. Change-Id: I19d8b8c3bc37cca6fb2c9e535e70b43dabef58d6
This commit is contained in:
parent
2980f52f1b
commit
bfc2681ad5
|
@ -0,0 +1,14 @@
|
|||
==================================
|
||||
Module - tripleo_container_configs
|
||||
==================================
|
||||
|
||||
|
||||
This module provides for the following ansible plugin:
|
||||
|
||||
* tripleo_container_configs
|
||||
|
||||
|
||||
.. ansibleautoplugin::
|
||||
:module: tripleo_ansible/ansible_plugins/modules/tripleo_container_configs.py
|
||||
:documentation: true
|
||||
:examples: true
|
|
@ -0,0 +1,92 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2020 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import os
|
||||
import yaml
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: tripleo_container_configs
|
||||
author:
|
||||
- "TripleO team"
|
||||
version_added: '2.9'
|
||||
short_description: Generate Container configs in JSON
|
||||
notes: []
|
||||
description:
|
||||
- It will generate the Container JSON configs from config-download data in
|
||||
YAML.
|
||||
requirements:
|
||||
- None
|
||||
options:
|
||||
config_data:
|
||||
description:
|
||||
- Content of kolla_config.yaml file (must be YAML format)
|
||||
type: dict
|
||||
required: true
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: Write container config json files
|
||||
tripleo_container_configs:
|
||||
config_data:
|
||||
/var/lib/kolla/config_files/ceilometer_agent_compute.json:
|
||||
command: /usr/bin/ceilometer-polling compute
|
||||
config_files:
|
||||
- dest: /
|
||||
merge: true
|
||||
preserve_properties: true
|
||||
source: /var/lib/kolla/config_files/src/*
|
||||
/var/lib/kolla/config_files/ceilometer_agent_notification.json:
|
||||
command: /usr/bin/ceilometer-agent-notification
|
||||
config_files:
|
||||
- dest: /
|
||||
merge: true
|
||||
preserve_properties: true
|
||||
source: /var/lib/kolla/config_files/src/*
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=yaml.safe_load(DOCUMENTATION)['options'],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
results = dict(
|
||||
changed=False
|
||||
)
|
||||
|
||||
# parse args
|
||||
args = module.params
|
||||
|
||||
# Set parameters
|
||||
config_data = args['config_data']
|
||||
|
||||
for path, config in config_data.items():
|
||||
with open(path, "wb") as config_file:
|
||||
config_file.write(json.dumps(config, indent=2).encode('utf-8'))
|
||||
os.chmod(path, 0o600)
|
||||
results['changed'] = True
|
||||
|
||||
module.exit_json(**results)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: Write container config json files
|
||||
tripleo_container_configs:
|
||||
config_data:
|
||||
/tmp/container_config1.json:
|
||||
command: /usr/bin/ceilometer-polling compute
|
||||
config_files:
|
||||
- dest: /
|
||||
merge: true
|
||||
preserve_properties: true
|
||||
source: /var/lib/kolla/config_files/src/*
|
||||
/tmp/container_config2.json:
|
||||
command: /usr/bin/ceilometer-agent-notification
|
||||
config_files:
|
||||
- dest: /
|
||||
merge: true
|
||||
preserve_properties: true
|
||||
source: /var/lib/kolla/config_files/src/*
|
||||
- name: Check that container_config1.json file was created
|
||||
stat:
|
||||
path: "/tmp/container_config1.json"
|
||||
register: st_config
|
||||
failed_when:
|
||||
- not st_config.stat.exists
|
||||
- name: Check that container_config1.json configuration is correct
|
||||
slurp:
|
||||
src: "/tmp/container_config1.json"
|
||||
register: slurp_config
|
||||
failed_when:
|
||||
- ('ceilometer-polling' not in slurp_config['content']|b64decode)
|
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
driver:
|
||||
name: delegated
|
||||
options:
|
||||
managed: false
|
||||
login_cmd_template: >-
|
||||
ssh
|
||||
-o UserKnownHostsFile=/dev/null
|
||||
-o StrictHostKeyChecking=no
|
||||
-o Compression=no
|
||||
-o TCPKeepAlive=yes
|
||||
-o VerifyHostKeyDNS=no
|
||||
-o ForwardX11=no
|
||||
-o ForwardAgent=no
|
||||
{instance}
|
||||
ansible_connection_options:
|
||||
ansible_connection: ssh
|
||||
|
||||
log: true
|
||||
|
||||
platforms:
|
||||
- name: instance
|
||||
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
fact_caching: jsonfile
|
||||
fact_caching_connection: /tmp/molecule/facts
|
||||
inventory:
|
||||
hosts:
|
||||
all:
|
||||
hosts:
|
||||
instance:
|
||||
ansible_host: localhost
|
||||
log: true
|
||||
env:
|
||||
ANSIBLE_STDOUT_CALLBACK: yaml
|
||||
ANSIBLE_ROLES_PATH: "${ANSIBLE_ROLES_PATH:-/usr/share/ansible/roles}:${HOME}/zuul-jobs/roles"
|
||||
ANSIBLE_LIBRARY: "${ANSIBLE_LIBRARY:-/usr/share/ansible/plugins/modules}"
|
||||
ANSIBLE_FILTER_PLUGINS: "${ANSIBLE_FILTER_PLUGINS:-/usr/share/ansible/plugins/filter}"
|
||||
|
||||
scenario:
|
||||
name: tripleo_container_configs
|
||||
test_sequence:
|
||||
- prepare
|
||||
- converge
|
||||
|
||||
verifier:
|
||||
name: testinfra
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
# Copyright 2019 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
- name: Prepare
|
||||
hosts: all
|
||||
roles:
|
||||
- role: test_deps
|
Loading…
Reference in New Issue