Add network gateway validation
Check whether the gateway defined in `undercloud.conf` exists and is reachable. This validation demonstrates how to use the hiera facter to get the path to undercloud.conf file. Change-Id: I23f520baf0d787807ba7275c1b2e69a1a671529d Co-Authored-By: Tomas Sedovic <tsedovic@redhat.com> Depends-On: I78cdd1b9844a12ef43fee3d5967d00a7d9992b02
This commit is contained in:
parent
ad1439a68d
commit
2fca27633c
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
- hosts: undercloud
|
||||
vars:
|
||||
metadata:
|
||||
name: Check network_gateway on the provisioning network
|
||||
description: >
|
||||
If `network_gateway` in `undercloud.conf` is different from `local_ip`,
|
||||
verify that the gateway exists and is reachable.
|
||||
groups:
|
||||
- pre-instrospection
|
||||
tasks:
|
||||
- name: Get the path of tripleo undercloud config file
|
||||
become: true
|
||||
hiera: name="tripleo_undercloud_conf_file"
|
||||
- name: Gather undercloud.conf values
|
||||
undercloud_conf: undercloud_conf_path={{ tripleo_undercloud_conf_file }}
|
||||
- name: "Test network_gateway if different from local_ip"
|
||||
icmp_ping: host={{ undercloud_conf.DEFAULT.network_gateway }}
|
||||
when: >
|
||||
"{{ undercloud_conf.DEFAULT.local_ip | default('0.0.0.0') | ipaddr('address') }}"
|
||||
!=
|
||||
"{{ undercloud_conf.DEFAULT.network_gateway | default('0.0.0.0') | ipaddr('address') }}"
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2016 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.
|
||||
|
||||
import subprocess
|
||||
|
||||
from ansible.module_utils.basic import * # noqa
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(argument_spec=dict(
|
||||
name=dict(required=True, type='str'),
|
||||
))
|
||||
|
||||
name = module.params.get('name')
|
||||
|
||||
cmd = ['/usr/bin/hiera', name]
|
||||
result = subprocess.check_output(cmd).rstrip()
|
||||
|
||||
if result == 'nil':
|
||||
module.fail_json(msg="Failed to retrieve hiera data for {}"
|
||||
.format(name))
|
||||
|
||||
module.exit_json(changed=False,
|
||||
ansible_facts={name: result})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2016 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.
|
||||
|
||||
from ansible.module_utils.basic import * # noqa
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: icmp_ping
|
||||
short_description: ICMP ping remote hosts
|
||||
requirements: [ ping ]
|
||||
description:
|
||||
- Check host connectivity with ICMP ping.
|
||||
options:
|
||||
host:
|
||||
required: true
|
||||
description:
|
||||
- IP address or hostname of host to ping
|
||||
type: str
|
||||
author: "Martin Andre (@mandre)"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
# Ping host:
|
||||
- icmp: name=somegroup state=present
|
||||
- hosts: webservers
|
||||
tasks:
|
||||
- name: Check Internet connectivity
|
||||
ping: host="www.ansible.com"
|
||||
'''
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
host=dict(required=True, type='str'),
|
||||
)
|
||||
)
|
||||
|
||||
host = module.params.pop('host')
|
||||
result = module.run_command('ping -c 1 {}'.format(host))
|
||||
failed = (result[0] != 0)
|
||||
msg = result[1] if result[1] else result[2]
|
||||
|
||||
module.exit_json(changed=False, failed=failed, msg=msg)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2016 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.
|
||||
|
||||
import ConfigParser
|
||||
from os import path
|
||||
|
||||
from ansible.module_utils.basic import * # noqa
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(argument_spec=dict(
|
||||
undercloud_conf_path=dict(required=True, type='str'),
|
||||
))
|
||||
|
||||
undercloud_conf_path = module.params.get('undercloud_conf_path')
|
||||
|
||||
if path.exists(undercloud_conf_path) and path.isfile(undercloud_conf_path):
|
||||
config = ConfigParser.SafeConfigParser()
|
||||
config.read(undercloud_conf_path)
|
||||
|
||||
sections = ['DEFAULT'] + config.sections()
|
||||
result = dict(((section, dict(config.items(section)))
|
||||
for section in sections))
|
||||
|
||||
module.exit_json(changed=False,
|
||||
ansible_facts={u'undercloud_conf': result})
|
||||
else:
|
||||
module.fail_json(msg="Could not open the undercloud.conf file at '%s'"
|
||||
% undercloud_conf_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue