Updated the hostname generation
The change simply adds a more complete hostname within the "/etc/hosts" file for all nodes within inventory which ensures all hosts are reachable and have a proper host entry for itself and all other hosts. Additionally the hostname insert script has been made idempotent and tests have been added to ensure functionality. Partial-Bug: #1577245 Change-Id: Ib1e3b6f02758906e3ec7ab35737c1a58fcbca216 Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
parent
339fff1d8c
commit
ae02667b84
@ -68,3 +68,7 @@ openstack_kernel_options:
|
|||||||
- { key: 'net.ipv6.neigh.default.gc_interval', value: 60 }
|
- { key: 'net.ipv6.neigh.default.gc_interval', value: 60 }
|
||||||
- { key: 'net.ipv6.neigh.default.gc_stale_time', value: 120 }
|
- { key: 'net.ipv6.neigh.default.gc_stale_time', value: 120 }
|
||||||
- { key: 'fs.aio-max-nr', value: 131072 }
|
- { key: 'fs.aio-max-nr', value: 131072 }
|
||||||
|
|
||||||
|
# Set the openstack domain name
|
||||||
|
openstack_domain: openstack.local
|
||||||
|
|
||||||
|
22
manual-test.rc
Normal file
22
manual-test.rc
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
export VIRTUAL_ENV=$(pwd)
|
||||||
|
export ANSIBLE_HOST_KEY_CHECKING=False
|
||||||
|
export ANSIBLE_SSH_CONTROL_PATH=/tmp/%%h-%%r
|
||||||
|
|
||||||
|
# TODO (odyssey4me) These are only here as they are non-standard folder
|
||||||
|
# names for Ansible 1.9.x. We are using the standard folder names for
|
||||||
|
# Ansible v2.x. We can remove this when we move to Ansible 2.x.
|
||||||
|
export ANSIBLE_ACTION_PLUGINS=${HOME}/.ansible/plugins/action
|
||||||
|
export ANSIBLE_CALLBACK_PLUGINS=${HOME}/.ansible/plugins/callback
|
||||||
|
export ANSIBLE_FILTER_PLUGINS=${HOME}/.ansible/plugins/filter
|
||||||
|
export ANSIBLE_LOOKUP_PLUGINS=${HOME}/.ansible/plugins/lookup
|
||||||
|
|
||||||
|
# This is required as the default is the current path or a path specified
|
||||||
|
# in ansible.cfg
|
||||||
|
export ANSIBLE_LIBRARY=${HOME}/.ansible/plugins/library
|
||||||
|
|
||||||
|
# This is required as the default is '/etc/ansible/roles' or a path
|
||||||
|
# specified in ansible.cfg
|
||||||
|
export ANSIBLE_ROLES_PATH=${HOME}/.ansible/roles:$(pwd)/..
|
||||||
|
|
||||||
|
echo "Run manual functional tests by executing the following:"
|
||||||
|
echo "# ./.tox/functional/bin/ansible-playbook -i tests/inventory tests/test.yml -e \"rolename=$(pwd)\""
|
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- The option ``openstack_domain`` has been added to the
|
||||||
|
**openstack_hosts** role. This option is used to setup
|
||||||
|
proper hostname entries for all hosts within a given
|
||||||
|
OpenStack deployment.
|
||||||
|
- The **openstack_hosts** role will setup an RFC1034/5
|
||||||
|
hostname and create an alias for all hosts in inventory.
|
@ -19,5 +19,12 @@
|
|||||||
dest: "/usr/local/bin/openstack-host-hostfile-setup.sh"
|
dest: "/usr/local/bin/openstack-host-hostfile-setup.sh"
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
|
|
||||||
|
- name: Stat host file
|
||||||
|
stat:
|
||||||
|
path: /etc/hosts
|
||||||
|
register: stat_hosts
|
||||||
|
|
||||||
- name: Update hosts file
|
- name: Update hosts file
|
||||||
command: "/usr/local/bin/openstack-host-hostfile-setup.sh"
|
command: "/usr/local/bin/openstack-host-hostfile-setup.sh"
|
||||||
|
register: update_hosts
|
||||||
|
changed_when: stat_hosts.stat.md5 | string != update_hosts.stdout | string
|
||||||
|
@ -3,7 +3,52 @@
|
|||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
function insert_host_entry {
|
||||||
|
ENTRY=$1
|
||||||
|
ADDR=$2
|
||||||
|
if ! grep -q -o "^${ENTRY}$" /etc/hosts; then
|
||||||
|
echo "${ENTRY}" | tee -a /etc/hosts
|
||||||
|
elif ! grep -q -o "^${ADDR}\b" /etc/hosts; then
|
||||||
|
sed -i "s|^${ADDR}\b\ .*|${ENTRY}|" /etc/hosts
|
||||||
|
elif [[ "$(grep -o "^${ADDR}\b" /etc/hosts | wc -l)" -ge "2" ]]; then
|
||||||
|
sed -i "/^${IPADDR}\b/d" /etc/hosts
|
||||||
|
echo "${ENTRY}" | tee -a /etc/hosts
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function host_update {
|
||||||
|
ANSHOSTNAME=$1
|
||||||
|
RFCHOSTNAME=$2
|
||||||
|
INVHOSTNAME=$3
|
||||||
|
IPADDR=$4
|
||||||
|
DOMAINNAME=$5
|
||||||
|
|
||||||
|
if [[ "${ANSHOSTNAME}" != "${RFCHOSTNAME}" ]] && [[ "${RFCHOSTNAME}" != "${INVHOSTNAME}" ]]; then
|
||||||
|
insert_host_entry "${IPADDR} ${RFCHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME} ${INVHOSTNAME} ${ANSHOSTNAME}" "${IPADDR}"
|
||||||
|
elif [[ "${ANSHOSTNAME}" != "${RFCHOSTNAME}" ]] && [[ "${RFCHOSTNAME}" == "${INVHOSTNAME}" ]]; then
|
||||||
|
insert_host_entry "${IPADDR} ${RFCHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME} ${ANSHOSTNAME}" "${IPADDR}"
|
||||||
|
elif [[ "${ANSHOSTNAME}" == "${RFCHOSTNAME}" ]] && [[ "${RFCHOSTNAME}" == "${INVHOSTNAME}" ]]; then
|
||||||
|
insert_host_entry "${IPADDR} ${RFCHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME}" "${IPADDR}"
|
||||||
|
else
|
||||||
|
insert_host_entry "${IPADDR} ${RFCHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME} ${INVHOSTNAME}" "${IPADDR}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
{% set host_rfc_1034_1035_name = inventory_hostname|replace('_', '-') %}
|
||||||
|
host_update "{{ ansible_hostname|default(host_rfc_1034_1035_name) }}" \
|
||||||
|
"{{ host_rfc_1034_1035_name }}" \
|
||||||
|
"{{ inventory_hostname }}" \
|
||||||
|
"127.0.1.1" \
|
||||||
|
"{{ openstack_domain }}"
|
||||||
|
|
||||||
{% for item in groups['all'] %}
|
{% for item in groups['all'] %}
|
||||||
sed -i '/^{{ hostvars[item]["ansible_ssh_host"] }} .*/d' /etc/hosts
|
{% set target_rfc_1034_1035_name = item|replace('_', '-') %}
|
||||||
echo '{{ hostvars[item]["ansible_ssh_host"] }} {{ item }}' | tee -a /etc/hosts
|
host_update "{{ hostvars[item]['ansible_hostname']|default(target_rfc_1034_1035_name) }}" \
|
||||||
|
"{{ target_rfc_1034_1035_name }}" \
|
||||||
|
"{{ item }}" \
|
||||||
|
"{{ hostvars[item]['ansible_ssh_host'] }}" \
|
||||||
|
"{{ openstack_domain }}"
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
md5sum /etc/hosts|awk '{print $1}'
|
||||||
|
@ -67,8 +67,9 @@
|
|||||||
that:
|
that:
|
||||||
- "'dm_multipath' in modules_content"
|
- "'dm_multipath' in modules_content"
|
||||||
- "'vm.swappiness' in sysctl_content"
|
- "'vm.swappiness' in sysctl_content"
|
||||||
- "'127.111.111.101 test1' in hosts_content"
|
- "'127.111.111.101 test1.openstack.local test1' in hosts_content"
|
||||||
- "'127.111.111.102 test2' in hosts_content"
|
- "'127.111.111.102 test2.openstack.local test2' in hosts_content"
|
||||||
|
- "'127.0.1.1 localhost.openstack.local localhost' in hosts_content"
|
||||||
- "release_file.stat.exists"
|
- "release_file.stat.exists"
|
||||||
- "systat_file.stat.exists"
|
- "systat_file.stat.exists"
|
||||||
- "'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' in environment_content"
|
- "'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' in environment_content"
|
||||||
|
5
tox.ini
5
tox.ini
@ -15,6 +15,7 @@ whitelist_externals =
|
|||||||
bash
|
bash
|
||||||
git
|
git
|
||||||
rm
|
rm
|
||||||
|
wget
|
||||||
setenv =
|
setenv =
|
||||||
VIRTUAL_ENV={envdir}
|
VIRTUAL_ENV={envdir}
|
||||||
ANSIBLE_HOST_KEY_CHECKING = False
|
ANSIBLE_HOST_KEY_CHECKING = False
|
||||||
@ -108,12 +109,16 @@ commands =
|
|||||||
rm -rf {homedir}/.ansible
|
rm -rf {homedir}/.ansible
|
||||||
git clone https://git.openstack.org/openstack/openstack-ansible-plugins \
|
git clone https://git.openstack.org/openstack/openstack-ansible-plugins \
|
||||||
{homedir}/.ansible/plugins
|
{homedir}/.ansible/plugins
|
||||||
|
# This plugin makes the ansible-playbook output easier to read
|
||||||
|
wget -O {homedir}/.ansible/plugins/callback/human_log.py \
|
||||||
|
https://gist.githubusercontent.com/cliffano/9868180/raw/f360f306b3c6d689734a6aa8773a00edf16a0054/human_log.py
|
||||||
ansible-galaxy install \
|
ansible-galaxy install \
|
||||||
--role-file={toxinidir}/tests/ansible-role-requirements.yml \
|
--role-file={toxinidir}/tests/ansible-role-requirements.yml \
|
||||||
--ignore-errors \
|
--ignore-errors \
|
||||||
--force
|
--force
|
||||||
ansible-playbook -i {toxinidir}/tests/inventory \
|
ansible-playbook -i {toxinidir}/tests/inventory \
|
||||||
-e "rolename={toxinidir}" \
|
-e "rolename={toxinidir}" \
|
||||||
|
-vv \
|
||||||
{toxinidir}/tests/test.yml
|
{toxinidir}/tests/test.yml
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user