summaryrefslogtreecommitdiffstats
path: root/playbooks/libvirt/openshift-cluster
diff options
context:
space:
mode:
authorTroy Dawson <tdawson@redhat.com>2015-04-16 16:19:02 -0500
committerTroy Dawson <tdawson@redhat.com>2015-04-16 16:19:02 -0500
commit7f7b582a7bc239e69c147b98c8c2512050f12851 (patch)
treef0701e3ce7a42761e9dfb59218057a46e48a901b /playbooks/libvirt/openshift-cluster
parentdb9cf8ef4f030f30391e021f360fe0c3db1dce74 (diff)
parent0722304b2f9c94a2f70054e0a3c7feceaedb195c (diff)
downloadopenshift-7f7b582a7bc239e69c147b98c8c2512050f12851.tar.gz
openshift-7f7b582a7bc239e69c147b98c8c2512050f12851.tar.bz2
openshift-7f7b582a7bc239e69c147b98c8c2512050f12851.tar.xz
openshift-7f7b582a7bc239e69c147b98c8c2512050f12851.zip
Merge pull request #158 from openshift/master
Merge master into INT for first v3 INT deploy
Diffstat (limited to 'playbooks/libvirt/openshift-cluster')
l---------playbooks/libvirt/openshift-cluster/filter_plugins1
-rw-r--r--playbooks/libvirt/openshift-cluster/launch.yml65
-rw-r--r--playbooks/libvirt/openshift-cluster/launch_instances.yml102
-rw-r--r--playbooks/libvirt/openshift-cluster/list.yml43
l---------playbooks/libvirt/openshift-cluster/roles1
-rw-r--r--playbooks/libvirt/openshift-cluster/terminate.yml41
-rw-r--r--playbooks/libvirt/openshift-cluster/vars.yml7
7 files changed, 260 insertions, 0 deletions
diff --git a/playbooks/libvirt/openshift-cluster/filter_plugins b/playbooks/libvirt/openshift-cluster/filter_plugins
new file mode 120000
index 000000000..99a95e4ca
--- /dev/null
+++ b/playbooks/libvirt/openshift-cluster/filter_plugins
@@ -0,0 +1 @@
+../../../filter_plugins \ No newline at end of file
diff --git a/playbooks/libvirt/openshift-cluster/launch.yml b/playbooks/libvirt/openshift-cluster/launch.yml
new file mode 100644
index 000000000..6f2df33af
--- /dev/null
+++ b/playbooks/libvirt/openshift-cluster/launch.yml
@@ -0,0 +1,65 @@
+- name: Launch instance(s)
+ hosts: localhost
+ connection: local
+ gather_facts: no
+
+ vars:
+ libvirt_storage_pool_path: "{{ lookup('env','HOME') }}/libvirt-storage-pool-openshift"
+ libvirt_storage_pool: 'openshift'
+ libvirt_uri: 'qemu:///system'
+
+ vars_files:
+ - vars.yml
+
+ tasks:
+ - set_fact:
+ k8s_type: master
+
+ - name: Generate master instance name(s)
+ set_fact:
+ scratch_name: "{{ cluster_id }}-{{ k8s_type }}-{{ '%05x' | format( 1048576 | random ) }}"
+ register: master_names_output
+ with_sequence: start=1 end='{{ num_masters }}'
+
+ - set_fact:
+ master_names: "{{ master_names_output.results | oo_collect('ansible_facts') | oo_collect('scratch_name') }}"
+
+ - include: launch_instances.yml
+ vars:
+ instances: '{{ master_names }}'
+ cluster: '{{ cluster_id }}'
+ type: '{{ k8s_type }}'
+ group_name: 'tag_env-host-type-{{ cluster_id }}-openshift-master'
+
+ - set_fact:
+ k8s_type: node
+
+ - name: Generate node instance name(s)
+ set_fact:
+ scratch_name: "{{ cluster_id }}-{{ k8s_type }}-{{ '%05x' | format( 1048576 | random ) }}"
+ register: node_names_output
+ with_sequence: start=1 end='{{ num_nodes }}'
+
+ - set_fact:
+ node_names: "{{ node_names_output.results | oo_collect('ansible_facts') | oo_collect('scratch_name') }}"
+
+ - include: launch_instances.yml
+ vars:
+ instances: '{{ node_names }}'
+ cluster: '{{ cluster_id }}'
+ type: '{{ k8s_type }}'
+
+- hosts: 'tag_env-{{ cluster_id }}'
+ roles:
+ - openshift_repos
+ - os_update_latest
+
+- include: ../openshift-master/config.yml
+ vars:
+ oo_host_group_exp: 'groups["tag_env-host-type-{{ cluster_id }}-openshift-master"]'
+ oo_env: '{{ cluster_id }}'
+
+- include: ../openshift-node/config.yml
+ vars:
+ oo_host_group_exp: 'groups["tag_env-host-type-{{ cluster_id }}-openshift-node"]'
+ oo_env: '{{ cluster_id }}'
diff --git a/playbooks/libvirt/openshift-cluster/launch_instances.yml b/playbooks/libvirt/openshift-cluster/launch_instances.yml
new file mode 100644
index 000000000..3bbcae981
--- /dev/null
+++ b/playbooks/libvirt/openshift-cluster/launch_instances.yml
@@ -0,0 +1,102 @@
+- name: Create the libvirt storage directory for openshift
+ file:
+ dest: '{{ libvirt_storage_pool_path }}'
+ state: directory
+
+- name: Download Base Cloud image
+ get_url:
+ url: '{{ base_image_url }}'
+ sha256sum: '{{ base_image_sha256 }}'
+ dest: '{{ libvirt_storage_pool_path }}/{{ base_image_name }}'
+
+- name: Create the cloud-init config drive path
+ file:
+ dest: '{{ libvirt_storage_pool_path }}/{{ item }}_configdrive/openstack/latest'
+ state: directory
+ with_items: '{{ instances }}'
+
+- name: Create the cloud-init config drive files
+ template:
+ src: '{{ item[1] }}'
+ dest: '{{ libvirt_storage_pool_path }}/{{ item[0] }}_configdrive/openstack/latest/{{ item[1] }}'
+ with_nested:
+ - '{{ instances }}'
+ - [ user-data, meta-data ]
+
+- name: Create the cloud-init config drive
+ command: 'genisoimage -output {{ libvirt_storage_pool_path }}/{{ item }}_cloud-init.iso -volid cidata -joliet -rock user-data meta-data'
+ args:
+ chdir: '{{ libvirt_storage_pool_path }}/{{ item }}_configdrive/openstack/latest'
+ creates: '{{ libvirt_storage_pool_path }}/{{ item }}_cloud-init.iso'
+ with_items: '{{ instances }}'
+
+- name: Create the libvirt storage pool for openshift
+ command: 'virsh -c {{ libvirt_uri }} pool-create-as {{ libvirt_storage_pool }} dir --target {{ libvirt_storage_pool_path }}'
+ ignore_errors: yes
+
+- name: Refresh the libvirt storage pool for openshift
+ command: 'virsh -c {{ libvirt_uri }} pool-refresh {{ libvirt_storage_pool }}'
+
+- name: Create VMs drives
+ command: 'virsh -c {{ libvirt_uri }} vol-create-as {{ libvirt_storage_pool }} {{ item }}.qcow2 10G --format qcow2 --backing-vol {{ base_image_name }} --backing-vol-format qcow2'
+ with_items: '{{ instances }}'
+
+- name: Create VMs
+ virt:
+ name: '{{ item }}'
+ command: define
+ xml: "{{ lookup('template', '../templates/domain.xml') }}"
+ uri: '{{ libvirt_uri }}'
+ with_items: '{{ instances }}'
+
+- name: Start VMs
+ virt:
+ name: '{{ item }}'
+ state: running
+ uri: '{{ libvirt_uri }}'
+ with_items: '{{ instances }}'
+
+- name: Collect MAC addresses of the VMs
+ shell: 'virsh -c {{ libvirt_uri }} dumpxml {{ item }} | xmllint --xpath "string(//domain/devices/interface/mac/@address)" -'
+ register: scratch_mac
+ with_items: '{{ instances }}'
+
+- name: Wait for the VMs to get an IP
+ command: "egrep -c '{{ scratch_mac.results | oo_collect('stdout') | join('|') }}' /proc/net/arp"
+ ignore_errors: yes
+ register: nb_allocated_ips
+ until: nb_allocated_ips.stdout == '{{ instances | length }}'
+ retries: 30
+ delay: 1
+
+- name: Collect IP addresses of the VMs
+ shell: "awk '/{{ item.stdout }}/ {print $1}' /proc/net/arp"
+ register: scratch_ip
+ with_items: '{{ scratch_mac.results }}'
+
+- set_fact:
+ ips: "{{ scratch_ip.results | oo_collect('stdout') }}"
+
+- name: Add new instances
+ add_host:
+ hostname: '{{ item.0 }}'
+ ansible_ssh_host: '{{ item.1 }}'
+ ansible_ssh_user: root
+ groups: 'tag_env-{{ cluster }}, tag_host-type-{{ type }}, tag_env-host-type-{{ cluster }}-openshift-{{ type }}'
+ with_together:
+ - instances
+ - ips
+
+- name: Wait for ssh
+ wait_for:
+ host: '{{ item }}'
+ port: 22
+ with_items: ips
+
+- name: Wait for root user setup
+ command: 'ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null root@{{ item }} echo root user is setup'
+ register: result
+ until: result.rc == 0
+ retries: 30
+ delay: 1
+ with_items: ips
diff --git a/playbooks/libvirt/openshift-cluster/list.yml b/playbooks/libvirt/openshift-cluster/list.yml
new file mode 100644
index 000000000..6bf07e3c6
--- /dev/null
+++ b/playbooks/libvirt/openshift-cluster/list.yml
@@ -0,0 +1,43 @@
+- name: Generate oo_list_hosts group
+ hosts: localhost
+ connection: local
+ gather_facts: no
+
+ vars:
+ libvirt_uri: 'qemu:///system'
+
+ tasks:
+ - name: List VMs
+ virt:
+ command: list_vms
+ register: list_vms
+
+ - name: Collect MAC addresses of the VMs
+ shell: 'virsh -c {{ libvirt_uri }} dumpxml {{ item }} | xmllint --xpath "string(//domain/devices/interface/mac/@address)" -'
+ register: scratch_mac
+ with_items: '{{ list_vms.list_vms }}'
+ when: item|truncate(cluster_id|length+1, True) == '{{ cluster_id }}-...'
+
+ - name: Collect IP addresses of the VMs
+ shell: "awk '/{{ item.stdout }}/ {print $1}' /proc/net/arp"
+ register: scratch_ip
+ with_items: '{{ scratch_mac.results }}'
+ when: item.skipped is not defined
+
+ - name: Add hosts
+ add_host:
+ hostname: '{{ item[0] }}'
+ ansible_ssh_host: '{{ item[1].stdout }}'
+ ansible_ssh_user: root
+ groups: oo_list_hosts
+ with_together:
+ - '{{ list_vms.list_vms }}'
+ - '{{ scratch_ip.results }}'
+ when: item[1].skipped is not defined
+
+- name: List Hosts
+ hosts: oo_list_hosts
+
+ tasks:
+ - debug:
+ msg: 'public:{{ansible_default_ipv4.address}} private:{{ansible_default_ipv4.address}}'
diff --git a/playbooks/libvirt/openshift-cluster/roles b/playbooks/libvirt/openshift-cluster/roles
new file mode 120000
index 000000000..20c4c58cf
--- /dev/null
+++ b/playbooks/libvirt/openshift-cluster/roles
@@ -0,0 +1 @@
+../../../roles \ No newline at end of file
diff --git a/playbooks/libvirt/openshift-cluster/terminate.yml b/playbooks/libvirt/openshift-cluster/terminate.yml
new file mode 100644
index 000000000..c609169d3
--- /dev/null
+++ b/playbooks/libvirt/openshift-cluster/terminate.yml
@@ -0,0 +1,41 @@
+- name: Terminate instance(s)
+ hosts: localhost
+ connection: local
+ gather_facts: no
+
+ vars:
+ libvirt_storage_pool_path: "{{ lookup('env','HOME') }}/libvirt-storage-pool-openshift"
+ libvirt_storage_pool: 'openshift'
+ libvirt_uri: 'qemu:///system'
+
+ tasks:
+ - name: List VMs
+ virt:
+ command: list_vms
+ register: list_vms
+
+ - name: Destroy VMs
+ virt:
+ name: '{{ item[0] }}'
+ command: '{{ item[1] }}'
+ uri: '{{ libvirt_uri }}'
+ with_nested:
+ - '{{ list_vms.list_vms }}'
+ - [ destroy, undefine ]
+ when: item[0]|truncate(cluster_id|length+1, True) == '{{ cluster_id }}-...'
+
+ - name: Delete VMs config drive
+ file:
+ path: '{{ libvirt_storage_pool_path }}/{{ item }}_configdrive/openstack'
+ state: absent
+ with_items: '{{ list_vms.list_vms }}'
+ when: item|truncate(cluster_id|length+1, True) == '{{ cluster_id }}-...'
+
+ - name: Delete VMs drives
+ command: 'virsh -c {{ libvirt_uri }} vol-delete --pool {{ libvirt_storage_pool }} {{ item[0] }}{{ item[1] }}'
+ args:
+ removes: '{{ libvirt_storage_pool_path }}/{{ item[0] }}{{ item[1] }}'
+ with_nested:
+ - '{{ list_vms.list_vms }}'
+ - [ '_configdrive', '_cloud-init.iso', '.qcow2' ]
+ when: item[0]|truncate(cluster_id|length+1, True) == '{{ cluster_id }}-...'
diff --git a/playbooks/libvirt/openshift-cluster/vars.yml b/playbooks/libvirt/openshift-cluster/vars.yml
new file mode 100644
index 000000000..4e4eecd46
--- /dev/null
+++ b/playbooks/libvirt/openshift-cluster/vars.yml
@@ -0,0 +1,7 @@
+# base_image_url: http://download.fedoraproject.org/pub/fedora/linux/releases/21/Cloud/Images/x86_64/Fedora-Cloud-Base-20141203-21.x86_64.qcow2
+# base_image_name: Fedora-Cloud-Base-20141203-21.x86_64.qcow2
+# base_image_sha256: 3a99bb89f33e3d4ee826c8160053cdb8a72c80cd23350b776ce73cd244467d86
+
+base_image_url: http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2
+base_image_name: CentOS-7-x86_64-GenericCloud.qcow2
+base_image_sha256: e324e3ab1d24a1bbf035ddb365e7f9058c0b454acf48d7aa15c5519fae5998ab