Browse Source

add example around inventory variables

master
Nicolas Massé 7 years ago
parent
commit
f6d64dd419
  1. 1
      Jinja-Template-Iterate-over-Inventory/haproxy.cfg
  2. 27
      Jinja-Template-Iterate-over-Inventory/hosts
  3. 24
      Jinja-Template-Iterate-over-Inventory/playbook.yml

1
Jinja-Template-Iterate-over-Inventory/haproxy.cfg

@ -0,0 +1 @@
# BLA BLA BLA

27
Jinja-Template-Iterate-over-Inventory/hosts

@ -0,0 +1,27 @@
[masters]
ose3-master[1:3].test.example.com
[etcd]
ose3-master[1:3].test.example.com
[nodes]
ose3-master[1:3].test.example.com
ose3-infra[1:2].test.example.com openshift_node_labels="{'region': 'infra', 'zone': 'default'}"
ose3-node[1:2].test.example.com openshift_node_labels="{'region': 'primary', 'zone': 'default'}"
[nfs]
ose3-master1.test.example.com
[lb]
ose3-lb.test.example.com
# Create an OSEv3 group that contains the masters and nodes groups
[OSEv3:children]
masters
nodes
etcd
lb
nfs
[OSEv3:vars]
# BLA BLA BLA

24
Jinja-Template-Iterate-over-Inventory/playbook.yml

@ -0,0 +1,24 @@
- hosts: localhost
tasks:
- name: Add conf haproxy for infra node
blockinfile:
path: '{{ playbook_dir }}/haproxy.cfg'
marker: "# {mark} Add haproxy conf"
insertafter: "EOF"
content: |
frontend atomic-openshift-web
bind *:80
bind *:443
default_backend atomic-openshift-web
mode tcp
option tcplog
backend atomic-openshift-web
balance source
mode tcp
{% for item in groups['nodes'] -%}
{%- set node_labels = hostvars[item]['openshift_node_labels']|default({}) -%}
{%- if 'region' in node_labels and node_labels['region'] == "infra" %}
server {{ hostvars[item]['inventory_hostname_short'] }} {{ hostvars[item]['inventory_hostname'] }}
{% endif -%}
{%- endfor -%}
Loading…
Cancel
Save