Add tripleo-hosts-entries role
Add a new role to manage /etc/hosts entries. Instead of these entries being calculated by Heat, a jinja2 expression is used to construct the individual hosts entries for each overcloud nodes. Some data still comes out of Heat, such as those for the undercloud, vips, and extra hosts entries used for multi-stack. As such, variables are used for these entries so that the role can add them to /etc/hosts. Change-Id: I1e12962e2f2fa6c1a2b429a3e02424fd42b0a08d
This commit is contained in:
parent
2424c6d4a9
commit
207e350ca6
6
doc/source/roles/role-tripleo-hosts-entries.rst
Normal file
6
doc/source/roles/role-tripleo-hosts-entries.rst
Normal file
@ -0,0 +1,6 @@
|
||||
============================
|
||||
Role - tripleo-hosts-entries
|
||||
============================
|
||||
|
||||
.. ansibleautoplugin::
|
||||
:role: tripleo_ansible/roles/tripleo-hosts-entries
|
@ -0,0 +1,25 @@
|
||||
---
|
||||
# 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.
|
||||
|
||||
|
||||
# All variables intended for modification should be placed in this file.
|
||||
|
||||
# All variables within this role should have a prefix of "tripleo_hosts_entries"
|
||||
tripleo_hosts_entries_debug: false
|
||||
tripleo_hosts_entries_hosts_path: /etc/hosts
|
||||
tripleo_hosts_entries_undercloud_hosts_entries: ""
|
||||
tripleo_hosts_entries_extra_hosts_entries: ""
|
||||
tripleo_hosts_entries_vip_hosts_entries: ""
|
@ -0,0 +1,15 @@
|
||||
---
|
||||
# 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.
|
44
tripleo_ansible/roles/tripleo-hosts-entries/meta/main.yml
Normal file
44
tripleo_ansible/roles/tripleo-hosts-entries/meta/main.yml
Normal file
@ -0,0 +1,44 @@
|
||||
---
|
||||
# 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.
|
||||
|
||||
|
||||
galaxy_info:
|
||||
author: OpenStack
|
||||
description: TripleO OpenStack Role -- tripleo-hosts-entries
|
||||
company: Red Hat
|
||||
license: Apache-2.0
|
||||
min_ansible_version: 2.7
|
||||
#
|
||||
# Provide a list of supported platforms, and for each platform a list of versions.
|
||||
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
|
||||
# To view available platforms and versions (or releases), visit:
|
||||
# https://galaxy.ansible.com/api/v1/platforms/
|
||||
#
|
||||
platforms:
|
||||
- name: Fedora
|
||||
versions:
|
||||
- 28
|
||||
- name: CentOS
|
||||
versions:
|
||||
- 7
|
||||
|
||||
galaxy_tags:
|
||||
- tripleo
|
||||
|
||||
|
||||
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||
# if you add dependencies to this list.
|
||||
dependencies: []
|
@ -0,0 +1,37 @@
|
||||
# Molecule managed
|
||||
# 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.
|
||||
|
||||
|
||||
{% if item.registry is defined %}
|
||||
FROM {{ item.registry.url }}/{{ item.image }}
|
||||
{% else %}
|
||||
FROM {{ item.image }}
|
||||
{% endif %}
|
||||
|
||||
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
|
||||
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \
|
||||
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
|
||||
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \
|
||||
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \
|
||||
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi
|
||||
|
||||
{% for pkg in item.easy_install | default([]) %}
|
||||
# install pip for centos where there is no python-pip rpm in default repos
|
||||
RUN easy_install {{ pkg }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
CMD ["sh", "-c", "while true; do sleep 10000; done"]
|
@ -0,0 +1,79 @@
|
||||
---
|
||||
driver:
|
||||
name: docker
|
||||
|
||||
log: true
|
||||
|
||||
platforms:
|
||||
- name: centos7
|
||||
hostname: centos7
|
||||
image: centos:7
|
||||
dockerfile: Dockerfile
|
||||
pkg_extras: python-setuptools
|
||||
easy_install:
|
||||
- pip
|
||||
environment: &env
|
||||
http_proxy: "{{ lookup('env', 'http_proxy') }}"
|
||||
https_proxy: "{{ lookup('env', 'https_proxy') }}"
|
||||
|
||||
- name: fedora28
|
||||
hostname: fedora28
|
||||
image: fedora:28
|
||||
dockerfile: Dockerfile
|
||||
pkg_extras: python*-setuptools
|
||||
environment:
|
||||
<<: *env
|
||||
|
||||
provisioner:
|
||||
name: ansible
|
||||
log: true
|
||||
env:
|
||||
ANSIBLE_STDOUT_CALLBACK: yaml
|
||||
inventory:
|
||||
hosts:
|
||||
all:
|
||||
vars:
|
||||
# use a tmp hosts path since /etc/hosts isn't writeable in the
|
||||
# molecule test containers
|
||||
tripleo_hosts_entries_hosts_path: /tmp/hosts
|
||||
tripleo_hosts_entries_undercloud_hosts_entries: []
|
||||
tripleo_hosts_entries_extra_hosts_entries: []
|
||||
tripleo_hosts_entries_vip_hosts_entries: []
|
||||
cloud_domain: localdomain
|
||||
role_networks:
|
||||
- ctlplane
|
||||
- InternalApi
|
||||
networks:
|
||||
ctlplane:
|
||||
name_lower: ctlplane
|
||||
InternalApi:
|
||||
name_lower: internal_api
|
||||
children:
|
||||
overcloud:
|
||||
hosts:
|
||||
fedora28:
|
||||
hostname_resolve_network: ctlplane
|
||||
ctlplane_ip: 192.168.24.1
|
||||
internal_api_ip: 172.17.0.1
|
||||
centos7:
|
||||
hostname_resolve_network: ctlplane
|
||||
ctlplane_ip: 192.168.24.2
|
||||
internal_api_ip: 172.17.0.2
|
||||
|
||||
|
||||
scenario:
|
||||
test_sequence:
|
||||
- destroy
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- verify
|
||||
- destroy
|
||||
|
||||
lint:
|
||||
enabled: false
|
||||
|
||||
verifier:
|
||||
name: ansible
|
||||
lint:
|
||||
name: ansible-lint
|
@ -0,0 +1,21 @@
|
||||
---
|
||||
# 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: Converge
|
||||
hosts: all
|
||||
roles:
|
||||
- role: "tripleo-hosts-entries"
|
@ -0,0 +1,21 @@
|
||||
---
|
||||
# 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
|
@ -0,0 +1,48 @@
|
||||
---
|
||||
# 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: Verify
|
||||
hosts: all
|
||||
become: true
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Check if hosts lines were written to hosts file
|
||||
lineinfile:
|
||||
path: /tmp/hosts
|
||||
line: "{{ item }}"
|
||||
register: hosts_result
|
||||
check_mode: true
|
||||
loop:
|
||||
- 192.168.24.2 centos7.localdomain centos7
|
||||
- 192.168.24.2 centos7.ctlplane.localdomain centos7.ctlplane
|
||||
- 172.17.0.2 centos7.internal_api.localdomain centos7.internal_api
|
||||
- 192.168.24.1 fedora28.localdomain fedora28
|
||||
- 192.168.24.1 fedora28.ctlplane.localdomain fedora28.ctlplane
|
||||
- 172.17.0.1 fedora28.internal_api.localdomain fedora28.internal_api
|
||||
|
||||
- name: slurp /tmp/hosts
|
||||
slurp:
|
||||
path: /tmp/hosts
|
||||
register: slurp_hosts
|
||||
|
||||
- name: Show /tmp/hosts
|
||||
debug:
|
||||
var: slurp_hosts['content'] | b64decode
|
||||
|
||||
- name: Fail if hosts was changed
|
||||
debug:
|
||||
msg: "hosts was changed"
|
||||
failed_when: hosts_result is changed
|
44
tripleo_ansible/roles/tripleo-hosts-entries/tasks/main.yml
Normal file
44
tripleo_ansible/roles/tripleo-hosts-entries/tasks/main.yml
Normal file
@ -0,0 +1,44 @@
|
||||
---
|
||||
# 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: Update /etc/hosts
|
||||
become: true
|
||||
blockinfile:
|
||||
create: true
|
||||
path: "{{ tripleo_hosts_entries_hosts_path }}"
|
||||
block: |
|
||||
{{ tripleo_hosts_entries_undercloud_hosts_entries | join('') }}
|
||||
|
||||
{{ tripleo_hosts_entries_vip_hosts_entries | join('') }}
|
||||
|
||||
{% for host in groups['overcloud'] %}
|
||||
{{ hostvars[host][hostvars[host]['hostname_resolve_network'] ~ '_ip'] ~ ' ' ~
|
||||
host ~ '.' ~ cloud_domain ~ ' ' ~ host }}
|
||||
{% if role_networks is not none %}
|
||||
{% for network in role_networks | default([]) %}
|
||||
{{ hostvars[host][networks[network]['name_lower'] ~ '_ip'] ~ ' ' ~
|
||||
host ~ '.' ~ networks[network]['name_lower'] ~ '.' ~ cloud_domain ~ ' ' ~
|
||||
host ~ '.' ~ networks[network]['name_lower'] }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{{ hostvars[host]['ctlplane_ip'] ~ ' ' ~
|
||||
host ~ '.ctlplane' ~ '.' ~ cloud_domain ~ ' ' ~ host ~ '.ctlplane' }}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
{{ tripleo_hosts_entries_extra_hosts_entries | join('') }}
|
||||
tags:
|
||||
- tripleo_hosts_entries
|
22
tripleo_ansible/roles/tripleo-hosts-entries/vars/main.yml
Normal file
22
tripleo_ansible/roles/tripleo-hosts-entries/vars/main.yml
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
# 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.
|
||||
|
||||
|
||||
# While options found within the vars/ path can be overridden using extra
|
||||
# vars, items within this path are considered part of the role and not
|
||||
# intended to be modified.
|
||||
|
||||
# All variables within this role should have a prefix of "tripleo_{{ role_name | replace('-', '_') }}"
|
@ -37,6 +37,7 @@
|
||||
- tripleo-ansible-centos-7-molecule-tripleo-sshd
|
||||
- tripleo-ansible-centos-7-molecule-backup-and-restore
|
||||
- tripleo-ansible-centos-7-molecule-tripleo-packages
|
||||
- tripleo-ansible-centos-7-molecule-tripleo-hosts-entries
|
||||
gate:
|
||||
jobs:
|
||||
- tripleo-ansible-centos-7-molecule-aide
|
||||
@ -74,6 +75,7 @@
|
||||
- tripleo-ansible-centos-7-molecule-tripleo-sshd
|
||||
- tripleo-ansible-centos-7-molecule-backup-and-restore
|
||||
- tripleo-ansible-centos-7-molecule-tripleo-packages
|
||||
- tripleo-ansible-centos-7-molecule-tripleo-hosts-entries
|
||||
name: tripleo-ansible-molecule-jobs
|
||||
- job:
|
||||
files:
|
||||
@ -329,3 +331,10 @@
|
||||
parent: tripleo-ansible-centos-7-base
|
||||
vars:
|
||||
tripleo_role_name: tripleo-packages
|
||||
- job:
|
||||
files:
|
||||
- ^tripleo_ansible/roles/tripleo-hosts-entries/.*
|
||||
name: tripleo-ansible-centos-7-molecule-tripleo-hosts-entries
|
||||
parent: tripleo-ansible-centos-7-base
|
||||
vars:
|
||||
tripleo_role_name: tripleo-hosts-entries
|
||||
|
Loading…
Reference in New Issue
Block a user