updated to support the enlisting of compute nodes into juju and XOS when they come on line
Change-Id: I2b1d51414a7e22b9709ea5f534ddef622e008a32
diff --git a/cord-head-playbook.yml b/cord-head-playbook.yml
index dd550c8..6b01f1f 100644
--- a/cord-head-playbook.yml
+++ b/cord-head-playbook.yml
@@ -48,3 +48,8 @@
- docker-compose
- xos-start
+- name: Set up Automated Compute Node Provisioning
+ hosts: head
+ roles:
+ - { role: automation-integration, when on_maas }
+
diff --git a/roles/automation-integration/files/do-enlist-compute-node b/roles/automation-integration/files/do-enlist-compute-node
new file mode 100644
index 0000000..66cafbc
--- /dev/null
+++ b/roles/automation-integration/files/do-enlist-compute-node
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+ID=$1
+HOSTNAME=$2
+LOG=/etc/maas/ansible/logs/$ID.log
+
+INV=$(tempfile)
+cat >$INV <<EO_INV
+[head]
+juju-head-node ansible_user={{ ansible_user_id }}
+
+[compute]
+$HOSTNAME ansible_user=ubuntu
+EO_INV
+
+echo "BEGIN INVENTORY FILE" >> $LOG
+cat $INV >> $LOG
+echo "END INVENTORY_FILE" >> $LOG
+
+echo "ANSIBLE_ROLES_PATH=/etc/maas/ansible/roles ansible-playbook --private-key=/etc/maas/ansible/id_rsa -i $INV /etc/maas/ansible/cord-compute-playbook.yml" >> $LOG
+
+ANSIBLE_ROLES_PATH=/etc/maas/ansible/roles ansible-playbook --private-key=/etc/maas/ansible/id_rsa -i $INV /etc/maas/ansible/cord-compute-playbook.yml >> $LOG
+RESULT=$?
+rm $INV
+
+exit $RESULT
diff --git a/roles/automation-integration/tasks/main.yml b/roles/automation-integration/tasks/main.yml
new file mode 100644
index 0000000..9f81631
--- /dev/null
+++ b/roles/automation-integration/tasks/main.yml
@@ -0,0 +1,78 @@
+---
+- name: Ensure Ansible Directories
+ become: yes
+ file:
+ path=/etc/maas/ansible/{{ item }}
+ state=directory
+ owner=maas
+ group=maas
+ mode=0755
+ with_items:
+ - roles
+ - vars
+ - library
+
+- name: Ensure XOS Cluster Enlist Script
+ become: yes
+ template:
+ src=files/do-enlist-compute-node
+ dest=/etc/maas/ansible/do-enlist-compute-node
+ owner=maas
+ group=maas
+ mode=0755
+
+- name: Copy Compute Node Playbook
+ become: yes
+ copy:
+ src=../../../cord-compute-playbook.yml
+ dest=/etc/maas/ansible
+ owner=maas
+ group=maas
+ mode=0644
+
+- name: Copy Required Ansible Libraries
+ become: yes
+ copy:
+ src=../../../library/{{ item }}
+ dest=/etc/maas/ansible/library
+ owner=maas
+ group=maas
+ mode=0644
+ with_items:
+ - juju_facts.py
+
+- name: Copy Required Ansible Roles
+ become: yes
+ copy:
+ src=../../../roles/{{ item }}
+ dest=/etc/maas/ansible/roles
+ owner=maas
+ group=maas
+ mode=0755
+ with_items:
+ - common-prep
+ - cloudlab-prep
+ - compute-prep
+ - dns-configure
+ - head-prep
+ - juju-compute-setup
+ - xos-compute-setup
+
+- name: Copy Required Ansible Variables
+ become: yes
+ copy:
+ src=../../../vars/{{ item }}
+ dest=/etc/maas/ansible/vars
+ owner=maas
+ group=maas
+ mode=0644
+ with_items:
+ - cord_defaults.yml
+ - cord.yml
+ - example_keystone.yml
+
+- name: Ensure JuJu and XOS Compute Node Provisioning
+ become: yes
+ lineinfile:
+ dest=/etc/maas/ansible/do-ansible
+ line='/etc/maas/ansible/do-enlist-compute-node $ID $HOSTNAME || exit $?'
diff --git a/vars/cord.yml b/vars/cord.yml
index 65b7f4a..036b59d 100644
--- a/vars/cord.yml
+++ b/vars/cord.yml
@@ -47,3 +47,6 @@
# turn this on, or override when running playbook with --extra-vars="on_cloudlab=True"
on_cloudlab: False
+
+# turn this off, or override when running playbook with --extra-vars="on_maas=False"
+on_maas: True