Make services optional

Some users will use infra-ansible for 3rd party, some others
will want a minimal infra with Gerrit.
Moreover, some services are going away with the advent of
Zuul v3.
As such, make the services definitions optional, so users can
really define what they want for the deploy.
Also, reworked the services to be a list, to be more easily
loopable with Ansible with_subelements.

Change-Id: I0097bf4d90350fbe53b94e27b2036d4b8083263a
This commit is contained in:
Ricardo Carrillo Cruz 2016-06-17 10:48:36 +00:00
parent 6c19c5162f
commit f859b1e47f
2 changed files with 60 additions and 40 deletions

View File

@ -1,10 +1,14 @@
---
services:
puppetmaster:
- name: puppetmaster.infra.test
gerrit:
- name: gerrit.infra.test
zuul:
- name: zuul.infra.test
nodepool:
- name: nodepool.infra.test
- name: puppetmaster
hosts:
- puppetmaster.infra.test
- name: gerrit
hosts:
- gerrit.infra.test
- name: zuul
hosts:
- zuul.infra.test
- name: jenkins
hosts:
- jenkins.infra.test

View File

@ -1,36 +1,52 @@
---
- name: Get Puppetmaster server name from infra config
set_fact: puppetmaster_name={{ services['puppetmaster'][0]['name'] }}
- name: Get Puppetmaster service definition from infra config
set_fact: puppetmaster_service={{ services | selectattr('name', 'equalto', 'puppetmaster') | list }}
- block:
- name: Get Puppetmaster server name
set_fact: puppetmaster_name={{ puppetmaster_service[0]['hosts'][0] }}
- 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
- name: Add "{{ puppetmaster_name }}" to infra and puppetmaster group and set inventory IP
add_host: name={{ puppetmaster_name }} ansible_ssh_host={{ puppetmaster_ip }} groups=infra,puppetmaster
when: puppetmaster_service
- name: Get Gerrit service definition from infra config
set_fact: gerrit_service={{ services | selectattr('name', 'equalto', 'gerrit') | list }}
- block:
- name: Get Gerrit server name from infra config
set_fact: gerrit_name={{ services['gerrit'][0]['name'] }}
set_fact: gerrit_name={{ gerrit_service[0]['hosts'][0] }}
- 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
when: gerrit_service
- name: Get Zuul service definition from infra config
set_fact: zuul_service={{ services | selectattr('name', 'equalto', 'zuul') | list }}
- block:
- name: Get Zuul server name from infra config
set_fact: zuul_name={{ services['zuul'][0]['name'] }}
set_fact: zuul_name={{ zuul_service[0]['hosts'][0] }}
- 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
when: zuul_service
- name: Get Jenkins service definition from infra config
set_fact: jenkins_service={{ services | selectattr('name', 'equalto', 'jenkins') | list }}
- block:
- name: Get Jenkins server name from infra config
set_fact: jenkins_name={{ services['jenkins'][0]['name'] }}
set_fact: jenkins_name={{ jenkins_service[0]['hosts'][0] }}
- 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
when: jenkins_service