You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hetzner-ansible/pmci-inventory-cluster.yml

59 lines
1.8 KiB
YAML

---
# Parameters:
# playbook inventory
# stage := the name of the stage (e.g. dev, int, qa, prod)
# tenant := object with tenant related data
# key :=
# name :=
# cluster := object with cluster specific data (optional)
# ...
# data := object with action specific data (optional)
# ...
#############################################################
# Creating inventory dynamically for given cluster
#############################################################
- hosts: localhost
gather_facts: false
connection: local
pre_tasks:
- name: "Print given variables <cluster>"
debug:
msg: "{{ cluster }}"
become: false
when:
- cluster is defined
- name: "Print given variables <data>"
debug:
msg: "{{ data }}"
become: false
when:
- data is defined
- name: "Check if ansible version is at least {{ ansible_minimal_version }}"
assert:
that:
- ansible_version.string is version(ansible_minimal_version, ">=")
msg: "The ansible version has to be at least {{ ansible_minimal_version }}"
# add virtual server to load stage specific variables as context
- name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts"
add_host:
name: "{{ stage }}-virtual-host-to-read-groups-vars"
groups:
- "stage_{{ stage }}"
changed_when: False
tasks:
- name: "Add hosts for given cluster"
add_host:
name: "{{ stage }}-{{ tenant.key }}-{{ cluster.key }}-{{ '%02d' | format(item|int) }}"
groups: "{{ ['stage_' + stage ] + [cluster.service] + cluster.features }}"
with_sequence: start=1 end={{ cluster.size | default(1) }}
changed_when: False
when:
- cluster is defined