Skip to content

Commit

Permalink
Add a playbook to convert inventory names from hyphens to underscores… (
Browse files Browse the repository at this point in the history
#215)

* Add a playbook to convert inventory names from hyphens to underscores for Ansible 2.8+ (for Issue #210)

* Moved inventory fix to main playbook. Updated inventory template to reflect change in naming convention

* Updated readme to reflect inventory changes

* Removed hyphen-to-underscore.yml playbook, as changes are in pf9-express.yml
  • Loading branch information
James Denton authored Jul 1, 2019
1 parent 645d15a commit 719e2eb
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 19 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bond_mode=1
bond_mtu=9000
## network bond configuration implemented if manage_network=True
[bond-config]
[bond_config]
## for single interface bond configuration
hv01 bond_members='eth1' bond_sub_interfaces='[{"vlanid":"100","ip":"10.0.0.11","mask":"255.255.255.0"}]'
Expand Down Expand Up @@ -159,18 +159,18 @@ This is where you can configure your Kubernetes cluster members under their own
## Kubernetes Groups
################################################################################################
[pmk:children]
k8s-master
k8s-worker
k8s_master
k8s_worker
## global variables defined in group_vars/containervisors.yml
## note: if the following variables are not defined, their tasks will be skipped
## - cluster_uuid
[k8s-master]
[k8s_master]
cv01 ansible_host=10.0.0.15
cv02 ansible_host=10.0.0.16
cv03 ansible_host=10.0.0.17
[k8s-worker]
[k8s_worker]
cv04 ansible_host=10.0.0.18 cluster_uuid=7273706d-afd5-44ea-8fbf-901ceb6bef27
cv05 ansible_host=10.0.0.19 cluster_uuid=7273706d-afd5-44ea-8fbf-901ceb6bef27
```
Expand Down
10 changes: 6 additions & 4 deletions lib/hosts.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
##
## Ansible Inventory
##
## NOTE: As of Ansible 2.8+, inventory names should not contain hyphens.
##
[all]
[all:vars]
Expand Down Expand Up @@ -67,17 +69,17 @@ hv02 cinder_ip=10.0.4.14 pvs=["/dev/sdb","/dev/sdc","/dev/sdd","/dev/sde"]
## Kubernetes Groups
################################################################################################
[pmk:children]
k8s-master
k8s-worker
k8s_master
k8s_worker

## global variables defined in group_vars/containervisors.yml
## note: if the following variables are not defined, their tasks will be skipped
## - cluster_uuid
[k8s-master]
[k8s_master]
cv01 ansible_host=10.0.0.15
cv02 ansible_host=10.0.0.16
cv03 ansible_host=10.0.0.17

[k8s-worker]
[k8s_worker]
cv04 ansible_host=10.0.0.18 cluster_uuid=7273706d-afd5-44ea-8fbf-901ceb6bef27
cv05 ansible_host=10.0.0.19 cluster_uuid=7273706d-afd5-44ea-8fbf-901ceb6bef27
69 changes: 59 additions & 10 deletions pf9-express.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
---
##
## pf9-express - Platform9 Systems, Inc. - https://www.platform9.com/
##
## This playbook can be used to deploy and manage Platform9's PMO and PMK products.
##

######################################################################
# Repair Inventory
#
# In Ansible 2.8+, hyphens are not allowed in inventory group names.
# The following tasks backup and repair the inventory file as needed.
# See Issue #210 for more information.
######################################################################

- hosts: all
any_errors_fatal: true
tasks:
- name: Grab all group names in inventory containing hyphens
shell: grep -E -o '\[.*?-.*?\]' {{ inventory_file }} | sed 's/[][]//g'
register: groups_list
failed_when: "groups_list.rc == 2"
changed_when: false
delegate_to: localhost
run_once: true

- debug:
msg: "The following group name/reference will be modified: {{ item }}"
with_items: "{{ groups_list.stdout_lines }}"
when: groups_list.stdout != ""
run_once: true

- name: Make a backup of the inventory file, if needed
copy:
src: "{{ inventory_file }}"
dest: "{{ inventory_file }}.{{ ansible_date_time.iso8601 }}.bak"
when: groups_list.stdout != ""
delegate_to: localhost
run_once: true

- name: Replace hyphens with underscores in inventory group names
replace:
path: "{{ inventory_file }}"
regexp: "{{ item }}"
replace: "{{ item | regex_replace('-','_') }}"
with_items: "{{ groups_list.stdout_lines }}"
when: groups_list.stdout != ""
delegate_to: localhost
run_once: true

# Common Roles
- hosts:
- hypervisors
- k8s-master
- k8s-worker
- k8s_master
- k8s_worker
become: true
gather_facts: False
pre_tasks:
Expand All @@ -14,17 +63,17 @@
# Run pre_flight_checks
- hosts:
- hypervisors
- k8s-master
- k8s-worker
- k8s_master
- k8s_worker
become: true
roles:
- pf9-auth

# Run pre_hook
- hosts:
- hypervisors
- k8s-master
- k8s-worker
- k8s_master
- k8s_worker
become: true
roles:
- pre-hook
Expand Down Expand Up @@ -86,7 +135,7 @@
- { role: "wait-for-convergence", when: autoreg == "on" }

# Kubernetes Master Nodes
- hosts: k8s-master
- hosts: k8s_master
become: true
roles:
- common
Expand All @@ -99,7 +148,7 @@
- { role: "k8s-cluster-attach", k8s_node_type: "master", when: autoreg == "on" }

# Kubernetes Worker Nodes
- hosts: k8s-worker
- hosts: k8s_worker
become: true
roles:
- common
Expand All @@ -114,8 +163,8 @@
# Run post_hook
- hosts:
- hypervisors
- k8s-master
- k8s-worker
- k8s_master
- k8s_worker
become: true
roles:
- post-hook

0 comments on commit 719e2eb

Please sign in to comment.