Skip to content

Commit

Permalink
Add support for Pbench installation
Browse files Browse the repository at this point in the history
  • Loading branch information
asyedham committed Dec 16, 2020
1 parent c8e9729 commit 65764ef
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 0 deletions.
3 changes: 3 additions & 0 deletions install/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[defaults]
host_key_checking = false
inventory = ~/.infrared/.workspaces/active/hosts
114 changes: 114 additions & 0 deletions install/boot_vms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---

# Playbook to create client and server vm on Openstack
#
# ansible-playbook boot_vms.yml

- hosts: localhost
tasks:
- name: Copy files to undercloud if they do not exist
copy:
src: "{{ playbook_dir}}/scripts/pass_auth.sh"
dest: "/home/stack/"
delegate_to: "{{ groups.undercloud|first }}"

- hosts: undercloud
gather_facts: yes
become: true
vars:
vm_password: centos
external_network: public
pre_tasks:
- name: install packages
package:
name: "{{ item }}"
state: present
loop:
- wget
- libguestfs-tools
- sshpass
- libvirt

- name: restart libvirt service
service:
name: libvirtd
state: restarted

roles:
- images
- flavors
- network
- create_vm

post_tasks:
- name: check router exists
shell: |
. {{ overcloudrc }}
openstack router list | grep 'r1'
register: router_exists
ignore_errors: yes

- debug:
msg: "{{ router_exists }}"

- name: router
shell: |
. {{ overcloudrc }}
openstack router create r1
cidr=10.0.0.0
subnet_id=`openstack subnet list -c ID -c Subnet -f value | grep $cidr | cut -d' ' -f1`
neutron router-interface-add r1 $subnet_id
neutron router-gateway-set r1 {{ external_network }}
when: router_exists.stdout == ""

- name: create floating ip for client and server
shell: |
. {{ overcloudrc }}
client_port_id=`openstack port show {{ ports[0] }} -c id -f value`
server_port_id=`openstack port show {{ ports[1] }} -c id -f value`
neutron floatingip-create --port-id $client_port_id {{ external_network }}
neutron floatingip-create --port-id $server_port_id {{ external_network }}
ignore_errors: yes

- name: get floating ip of server and client
shell: |
source /home/stack/overcloudrc
openstack server list | grep {{ item }} | cut -d \| -f 5 | cut -d \, -f 2 | awk '{$1=$1;print}'
register: vms_fip
with_items:
- "{{ vm_names }}"

- debug:
msg: "{{ vms_fip }}"

- name: get computes ip
shell: |
source /home/stack/stackrc
nova list | grep {{ item }} | cut -d \| -f 7 |cut -d \= -f 2 | awk '{$1=$1;print}'
register: computes_ip
with_items:
- "{{ compute_names }}"

- name: update user to root
lineinfile:
path: /home/stack/.ssh/config
regexp: ' User heat-admin'
line: ' User root'

- name: copy the ssh keys
shell: |
. {{ overcloudrc }}
echo '{{ vm_password }}' | sshpass ssh-copy-id -i /home/stack/.ssh/id_rsa -o 'StrictHostKeyChecking no' -f root@{{ item.stdout }}
with_items: "{{ vms_fip.results }}"

- name: get default route
shell: |
ip r | grep default | cut -d ' ' -f5
register: default_route

- name: flush iptables on undercloud and add masquerade rule
shell: |
sudo iptables -F
sudo iptables -t nat -L --line-numbers
sudo iptables -t nat -A POSTROUTING -o {{ default_route.stdout }} -j MASQUERADE
sudo iptables -t nat -A POSTROUTING -o br-ctlplane -j MASQUERADE
10 changes: 10 additions & 0 deletions install/filter_plugins/install_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def dict_remove_item( dict, item):
"""Remove an item from a dictionary."""
del dict[item]
return dict

class FilterModule(object):
def filters(self):
return {
'dict_remove_item': dict_remove_item,
}
25 changes: 25 additions & 0 deletions install/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
guest_image_name: pbench_image
# user can add the guest_image required below
guest_images:
pbench_image:
name: pbench_image
url: http://cloud.centos.org/centos/8/x86_64/images/CentOS-8-GenericCloud-8.2.2004-20200611.2.x86_64.qcow2
type: qcow2
convert_to_raw: false

# user can specify the hypervisor on which he wants to create client and server vm's
hypervisor_hostnames: [ 'compute-0.redhat.local', 'compute-1.redhat.local']

compute_names: ['compute-0', 'compute-1' ]

#name for the client and server
vm_names: [ client, server ]

overcloudrc: /home/stack/overcloudrc

ports: [ 'client_port', 'server_port']

dns_nameserver: 10.1.32.3

timeout: 30
12 changes: 12 additions & 0 deletions install/roles/create_vm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: create a vm's on specified hypervisors
shell: . {{ overcloudrc }}; openstack server create --hypervisor-hostname {{ item[0] }} --flavor pbench_flavor --image {{ guest_image_name }} --nic port-id={{ item[1].stdout }} --user-data /home/stack/pass_auth.sh {{ item[2] }}
with_together:
- "{{ hypervisor_hostnames }}"
- "{{ port_ids }}"
- "{{ vm_names }}"
ignore_errors: yes

- name: wait for vm to boot
wait_for:
timeout: "{{ timeout }}"
8 changes: 8 additions & 0 deletions install/roles/flavors/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Add flavors to OpenStack Cloud
# Ignore errors here incase the flavors already exist.

- name: Add flavors to overcloud
shell: . {{ overcloudrc }}; openstack flavor create --public {{ item.name }} --id auto --ram {{ item.ram }} --disk {{ item.disk }} --vcpus {{ item.cpu }}
with_items: "{{ pbench_flavors }}"
ignore_errors: true
7 changes: 7 additions & 0 deletions install/roles/flavors/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
pbench_flavors:
- name: pbench_flavor
cpu: 8
disk: 160
ram: 16384

39 changes: 39 additions & 0 deletions install/roles/images/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# Obtain/Upload guest_images to OpenStack Cloud

- name: Fetch image
get_url:
url: "{{ guest_images[item].url }}"
dest: "/home/stack/{{ guest_images[item].name }}.{{ guest_images[item].type }}"
with_items: "{{ guest_images }}"

- name: Determine if image exists
shell: . {{ overcloudrc }}; openstack image list | grep '{{ guest_images[item].name }}'
register: image_exists
ignore_errors: true
changed_when: false
with_items: "{{ guest_images }}"

- name: Remove image from dictionary of images if image exists
set_fact:
guest_images: "{{ guest_images|dict_remove_item(item[0]) }}"
when: item[0] in item[1].stdout and
item[1] is defined
with_nested:
- "{{ guest_images }}"
- "{{ image_exists.results }}"

- debug:
msg: "{{ guest_images }}"


- name: change the root password for qcow2 image
shell: |
export LIBGUESTFS_BACKEND=direct
virt-customize -a /home/stack/{{ guest_images[item].name }}.{{ guest_images[item].type }} --root-password password:"{{ vm_password }}"
with_items: "{{ guest_images }}"

- name: Upload image into cloud
shell: . {{ overcloudrc }}; openstack image create --public --disk-format={{ guest_images[item].type }} --container-format=bare {{ guest_images[item].name }} < /home/stack/{{ guest_images[item].name }}.{{ guest_images[item].type }}
ignore_errors: true
with_items: "{{ guest_images }}"
56 changes: 56 additions & 0 deletions install/roles/network/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---

#Create a network, subnet, ports for client and server vms

- name: Determine if network exists
shell: . {{ overcloudrc }}; openstack network list | grep '{{ network_name }}'
register: network_exists
ignore_errors: true

- debug:
msg: "{{ network_exists }}"

- name: create a network
shell: . {{ overcloudrc }}; neutron net-create '{{ network_name }}' | egrep '\sid\s' | awk '{print $4}'
register: network_id
when: network_exists.stdout == ""

- name: create subnet
shell: . {{ overcloudrc }}; neutron subnet-create --dns-nameserver {{ dns_nameserver }} {{ network_name }} 10.0.0.0/24
ignore_errors: yes

- name: Determine if ports exists
shell: . {{ overcloudrc }}; openstack port list | grep '{{ item }}'
register: port_exists
with_items: "{{ ports }}"
ignore_errors: true

- name: Create ports for client and server
shell: |
. {{ overcloudrc }}
openstack port create --no-security-group --disable-port-security --network {{ network_id.stdout }} {{ item.0 }} | egrep '\sid\s' | awk '{print $4}'
register: port_ids
when: item[1].stdout == ""
with_together:
- "{{ ports }}"
- "{{ port_exists.results }}"


- name: get port ids for client and server
shell: |
. {{ overcloudrc }}
openstack port list | grep "{{ item[0] }}" | cut -d \| -f 2 | awk '{$1=$1;print}'
register: port_ids
when: item[1].stdout != ""
with_together:
- "{{ ports }}"
- "{{ port_exists.results }}"


- debug:
msg: "{{ port_ids.results }}"

- name: set fact for port ids
set_fact:
port_ids: "{{ port_ids.results }}"

3 changes: 3 additions & 0 deletions install/roles/network/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

network_name: pbench_network
7 changes: 7 additions & 0 deletions install/scripts/pass_auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

sed -i s/^PasswordAuthentication.*/PasswordAuthentication\ yes/ /etc/ssh/sshd_config
systemctl restart sshd
cat /etc/ssh/sshd_config
echo "Enabled PasswordAuthentication"
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y

0 comments on commit 65764ef

Please sign in to comment.