Add generate infra dynamic inventory playbook/role
Some clouds may not have metadata enabled, or even have it but is not reliable. Force the user to define in infra_config.yml the services that make up the OpenStack Infra cloud. This will be in a dict named 'services', which will contain an entry for each OpenStack Infra service (puppetmaster, zuul, nodepool, etc). Change-Id: I9e3fe34684cd31bf1750ad8cf72e7e9090bfe087
This commit is contained in:
parent
efd0234300
commit
563123d788
6
generate_infra_dynamic_groups.yml
Normal file
6
generate_infra_dynamic_groups.yml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
# file: generate_infra_dynamic_groups.yml
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
roles:
|
||||
- { role: generate_infra_dynamic_groups }
|
10
infra_config.yml.sample
Normal file
10
infra_config.yml.sample
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
services:
|
||||
puppetmaster:
|
||||
- name: puppetmaster.infra.test
|
||||
gerrit:
|
||||
- name: gerrit.infra.test
|
||||
zuul:
|
||||
- name: zuul.infra.test
|
||||
nodepool:
|
||||
- name: nodepool.infra.test
|
3
roles/generate_infra_dynamic_groups/defaults/main.yml
Normal file
3
roles/generate_infra_dynamic_groups/defaults/main.yml
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
generate_static_inventory: no
|
||||
generate_static_inventory_path: ~/inventory
|
36
roles/generate_infra_dynamic_groups/tasks/main.yml
Normal file
36
roles/generate_infra_dynamic_groups/tasks/main.yml
Normal file
@ -0,0 +1,36 @@
|
||||
---
|
||||
- name: Get Puppetmaster server name from infra config
|
||||
set_fact: puppetmaster_name={{ services['puppetmaster'][0]['name'] }}
|
||||
- name: Get Puppetmaster server UUID from dynamic inventory
|
||||
set_fact: puppetmaster_uuid={{ groups[puppetmaster_name][0] }}
|
||||
- name: Get Puppetmaster server IP
|
||||
set_fact: puppetmaster_ip={{ hostvars[puppetmaster_uuid]['openstack']['public_v4'] }}
|
||||
- name: Add "{{ puppetmaster_name }}" to infra and puppetmaster groups and set inventory IP
|
||||
add_host: name={{ puppetmaster_name }} ansible_ssh_host={{ puppetmaster_ip }} groups=infra,puppetmaster
|
||||
|
||||
- name: Get Gerrit server name from infra config
|
||||
set_fact: gerrit_name={{ services['gerrit'][0]['name'] }}
|
||||
- name: Get Gerrit server UUID from dynamic inventory
|
||||
set_fact: gerrit_uuid={{ groups[gerrit_name][0] }}
|
||||
- name: Get Gerrit server IP
|
||||
set_fact: gerrit_ip={{ hostvars[gerrit_uuid]['openstack']['public_v4'] }}
|
||||
- name: Add "{{ gerrit_name }}" to infra and gerrit groups and set inventory IP
|
||||
add_host: name={{ gerrit_name }} ansible_ssh_host={{ gerrit_ip }} groups=infra,gerrit
|
||||
|
||||
- name: Get Zuul server name from infra config
|
||||
set_fact: zuul_name={{ services['zuul'][0]['name'] }}
|
||||
- name: Get Zuul server UUID from dynamic inventory
|
||||
set_fact: zuul_uuid={{ groups[zuul_name][0] }}
|
||||
- name: Get Zuul server IP
|
||||
set_fact: zuul_ip={{ hostvars[zuul_uuid]['openstack']['public_v4'] }}
|
||||
- name: Add "{{ zuul_name }}" to infra and zuul groups and set inventory IP
|
||||
add_host: name={{ zuul_name }} ansible_ssh_host={{ zuul_ip }} groups=infra,zuul
|
||||
|
||||
- name: Get Jenkins server name from infra config
|
||||
set_fact: jenkins_name={{ services['jenkins'][0]['name'] }}
|
||||
- name: Get Jenkins server UUID from dynamic inventory
|
||||
set_fact: jenkins_uuid={{ groups[jenkins_name][0] }}
|
||||
- name: Get Jenkins server IP
|
||||
set_fact: jenkins_ip={{ hostvars[jenkins_uuid]['openstack']['public_v4'] }}
|
||||
- name: Add "{{ jenkins_name }}" to infra and jenkins groups and set inventory IP
|
||||
add_host: name={{ jenkins_name }} ansible_ssh_host={{ jenkins_ip }} groups=infra,jenkins
|
@ -1,22 +1,2 @@
|
||||
---
|
||||
- name: Get hostname from server name
|
||||
set_fact: server_hostname={{ inventory_hostname.partition('.')[0] }}
|
||||
- name: Get server UUID from dynamic inventory
|
||||
set_fact: server_uuid={{ groups[inventory_hostname][0] }}
|
||||
- name: Get server IP
|
||||
set_fact: server_ip={{ hostvars[server_uuid]['openstack']['public_v4'] }}
|
||||
# Set hostname and /etc/hosts
|
||||
# Inspired by:
|
||||
# https://github.com/ansible/ansible/pull/8482)
|
||||
# https://gist.github.com/rothgar/8793800
|
||||
- name: Set /etc/hostname
|
||||
hostname: name="{{ server_hostname }}"
|
||||
|
||||
# " lovely lonely double-quote for fixing vim highlighting
|
||||
|
||||
- name: Add all infra hosts to /etc/hosts
|
||||
lineinfile: dest=/etc/hosts
|
||||
line='{{ server_ip }} {{ item }} {{ server_hostname }}'
|
||||
insertafter='^127\.0\.0\.1'
|
||||
state=present
|
||||
with_items: "{{ groups['infra'] }}"
|
||||
- template: src=hosts.j2 dest=/etc/hosts owner=root group=root mode=0644
|
||||
|
7
roles/set_hostnames/templates/hosts.j2
Normal file
7
roles/set_hostnames/templates/hosts.j2
Normal file
@ -0,0 +1,7 @@
|
||||
127.0.0.1 localhost
|
||||
{% for host in groups['infra'] %}
|
||||
{% set server_hostname = host.partition('.')[0] %}
|
||||
{% set server_uuid = groups[host][0] %}
|
||||
{% set server_ip = hostvars[server_uuid]['openstack']['public_v4'] %}
|
||||
{{ server_ip }} {{ host }} {{ server_hostname }}
|
||||
{% endfor %}
|
Loading…
Reference in New Issue
Block a user