From 719e2ebc871d81eb60ebd6af65f718d7edb6f995 Mon Sep 17 00:00:00 2001 From: James Denton Date: Mon, 1 Jul 2019 12:22:25 -0400 Subject: [PATCH] =?UTF-8?q?Add=20a=20playbook=20to=20convert=20inventory?= =?UTF-8?q?=20names=20from=20hyphens=20to=20underscores=E2=80=A6=20(#215)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- README.md | 10 +++---- lib/hosts.tpl | 10 ++++--- pf9-express.yml | 69 ++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 70 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 720e6787..43bb599a 100644 --- a/README.md +++ b/README.md @@ -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"}]' @@ -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 ``` diff --git a/lib/hosts.tpl b/lib/hosts.tpl index d6d959a6..f975dbd6 100644 --- a/lib/hosts.tpl +++ b/lib/hosts.tpl @@ -1,5 +1,7 @@ ## ## Ansible Inventory +## +## NOTE: As of Ansible 2.8+, inventory names should not contain hyphens. ## [all] [all:vars] @@ -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 diff --git a/pf9-express.yml b/pf9-express.yml index 965896e4..552f1655 100644 --- a/pf9-express.yml +++ b/pf9-express.yml @@ -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: @@ -14,8 +63,8 @@ # Run pre_flight_checks - hosts: - hypervisors - - k8s-master - - k8s-worker + - k8s_master + - k8s_worker become: true roles: - pf9-auth @@ -23,8 +72,8 @@ # Run pre_hook - hosts: - hypervisors - - k8s-master - - k8s-worker + - k8s_master + - k8s_worker become: true roles: - pre-hook @@ -86,7 +135,7 @@ - { role: "wait-for-convergence", when: autoreg == "on" } # Kubernetes Master Nodes -- hosts: k8s-master +- hosts: k8s_master become: true roles: - common @@ -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 @@ -114,8 +163,8 @@ # Run post_hook - hosts: - hypervisors - - k8s-master - - k8s-worker + - k8s_master + - k8s_worker become: true roles: - post-hook