Skip to content

Commit

Permalink
add playbook pbench agent bootstrap and
Browse files Browse the repository at this point in the history
pbench_agent install
  • Loading branch information
asyedham committed Dec 18, 2020
1 parent 65764ef commit 77fb63f
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 67 deletions.
1 change: 1 addition & 0 deletions install/ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[defaults]
host_key_checking = false
inventory = ~/.infrared/.workspaces/active/hosts
timeout = 120
38 changes: 16 additions & 22 deletions install/boot_vms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@
#
# 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: generate pass_auth.sh
template:
src: pass_auth.sh.j2
dest: "{{ user_dir }}/pass_auth.sh"
mode: a+rwx

- name: install packages
package:
name: "{{ item }}"
Expand Down Expand Up @@ -48,9 +46,6 @@
register: router_exists
ignore_errors: yes

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

- name: router
shell: |
. {{ overcloudrc }}
Expand All @@ -72,43 +67,42 @@

- name: get floating ip of server and client
shell: |
source /home/stack/overcloudrc
. {{ 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
. {{ 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
path: "{{ user_dir}}/.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 }}
echo '{{ vm_password }}' | sshpass ssh-copy-id -i {{ user_dir }}/.ssh/id_rsa -o 'StrictHostKeyChecking no' -f root@{{ item.stdout }}
with_items: "{{ vms_fip.results }}"
changed_when: false

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

- name: flush iptables on undercloud and add masquerade rule
become: true
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
iptables -F
iptables -t nat -L --line-numbers
iptables -t nat -A POSTROUTING -o {{ default_route.stdout }} -j MASQUERADE
iptables -t nat -A POSTROUTING -o br-ctlplane -j MASQUERADE
25 changes: 17 additions & 8 deletions install/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
---
guest_image_name: pbench_image
# user can add the guest_image required below
# user can add the guest_image url 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
url_centos8: http://cloud.centos.org/centos/8/x86_64/images/CentOS-8-GenericCloud-8.2.2004-20200611.2.x86_64.qcow2
url_centos7: http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.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']
# rhel 8
epel_repo:
el8: https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
el7: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

pbench_image_rhel: false

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

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

user_dir: /home/stack
overcloudrc: /home/stack/overcloudrc

stackrc: /home/stack/stackrc
# port names
ports: [ 'client_port', 'server_port']

dns_nameserver: 10.1.32.3

timeout: 30

# update the values to install pbench agent
#pbench_key_url:
#pbench_config_url:
#pbench_configuration_environment: "production"
59 changes: 59 additions & 0 deletions install/pbench_agent_bootstrap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
#
# Playbook for installing pbench_bootstrap
#
# Usage:
# ansible-playbook pbench_agent_bootstrap.yml -e "repos=<perf-dept-repo>"

- hosts: compute
tasks:
- name: copy the keys
shell: |
sudo cp -r ~/.ssh /root/
- hosts: undercloud
gather_facts: yes
tasks:
- name: clone perf-dept
shell: |
GIT_SSL_NO_VERIFY=true git clone {{ repos }}
ignore_errors: yes

- name: get computes ip
shell: |
. {{ 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: get floating ip of server and client
shell: |
. {{ 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 }}"

- name: copy the keys
shell: |
sudo cp -r ~/.ssh /root/
- name: create inventories
file:
path: "{{ user_dir }}/.config/Inventories/"
state: directory

- name: generate a inventory
template:
src: repo_bootstrap.hosts.j2
dest: "{{ user_dir }}/.config/Inventories/repo-bootstrap.hosts"

- name: run repo-bootstrap.yml
shell: |
ansible-playbook --user=root -i "{{ user_dir}}/.config/Inventories/repo-bootstrap.hosts" repo-bootstrap.yml
register: repo_bootstrap
args:
chdir: "{{ user_dir }}/perf-dept/sysadmin/Ansible"
- debug:
msg: "{{ repo_bootstrap }}"
95 changes: 95 additions & 0 deletions install/pbench_agent_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
#
# Playbook for pbench agent installations
# Usage:
# ansible-playbook pbench_agent_install.yml

- hosts: compute
gather_facts: yes
tasks:
- name: install latest epel-release
yum:
name: "{{ epel_repo.el7 }}"
state: present
become: yes
loop:
- "{{ epel_repo.el7 }}"
- perl-Data-UUID
when: ansible_distribution_major_version < '8'

- name: install perl-Data-UUID on Compute nodes
dnf:
name: perl-Data-UUID
state: present
when: ansible_distribution_major_version == '8'

- hosts: undercloud
vars:
pbench_agent_install: true

tasks:
- block:
- name: remove old epel-release
yum:
name: "{{item }}"
state: absent
become: yes
ignore_errors: yes
loop:
- epel-release
- ansible

- name: install latest epel-release
yum:
name: "{{ epel_repo.el7 }}"
state: present
become: yes

- name: install ansible 2.9
yum:
name: ansible
state: present
become: yes

when: ansible_distribution_major_version < '8'


- name: Install the pbench-agent roles from Galaxy
shell: |
ansible-galaxy collection install pbench.agent
export ANSIBLE_ROLES_PATH=$HOME/.ansible/collections/ansible_collections/pbench/agent/roles:$ANSIBLE_ROLES_PATH
- name: generate pbench agent playbook
template:
src: pbench_agent_install.yml.j2
dest: "{{ user_dir }}/.ansible/collections/ansible_collections/pbench/agent/roles/pbench_agent_install.yml"

- name: get computes ip
shell: |
. {{ 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: get floating ip of server and client
shell: |
. {{ 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 }}"

- name: create a inventory file
template:
src: repo_bootstrap.hosts.j2
dest: "{{ user_dir }}/.config/myhosts.inv"

- name: run the playbook pbench_agent_install.yml
shell: |
ansible-playbook -i ~/.config/myhosts.inv pbench_agent_install.yml
register: agent_install
args:
chdir: "{{ user_dir }}/.ansible/collections/ansible_collections/pbench/agent/roles/"
- debug:
msg: "{{ agent_install }}"
15 changes: 11 additions & 4 deletions install/roles/create_vm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
- 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] }}
- name: create a vm's
shell: . {{ overcloudrc }}; openstack server create --flavor pbench_flavor --image {{ guest_image_name }} --nic port-id={{ item[0].stdout }} --user-data {{ user_dir }}/pass_auth.sh {{ item[1] }}
with_together:
- "{{ hypervisor_hostnames }}"
- "{{ port_ids }}"
- "{{ port_ids.results }}"
- "{{ vm_names }}"
ignore_errors: yes

- name: create a vm's
shell: . {{ overcloudrc }}; openstack server create --flavor pbench_flavor --image {{ guest_image_name }} --nic port-id={{ item[0].stdout }} --user-data {{ user_dir }}/pass_auth.sh {{ item[1] }}
with_together:
- "{{ get_port_ids.results }}"
- "{{ vm_names }}"
ignore_errors: yes


- name: wait for vm to boot
wait_for:
timeout: "{{ timeout }}"
18 changes: 11 additions & 7 deletions install/roles/images/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@

- name: Fetch image
get_url:
url: "{{ guest_images[item].url }}"
url: "{{ guest_images[item].url_centos7 }}"
dest: "/home/stack/{{ guest_images[item].name }}.{{ guest_images[item].type }}"
with_items: "{{ guest_images }}"
when: ansible_distribution_major_version < '8'

- name: Fetch image
get_url:
url: "{{ guest_images[item].url_centos8 }}"
dest: "/home/stack/{{ guest_images[item].name }}.{{ guest_images[item].type }}"
with_items: "{{ guest_images }}"
when: ansible_distribution_major_version == '8'

- name: Determine if image exists
shell: . {{ overcloudrc }}; openstack image list | grep '{{ guest_images[item].name }}'
Expand All @@ -23,17 +31,13 @@
- "{{ 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 }}"
virt-customize -a {{user_dir }}/{{ 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 }}
shell: . {{ overcloudrc }}; openstack image create --public --disk-format={{ guest_images[item].type }} --container-format=bare {{ guest_images[item].name }} < {{ user_dir }}/{{ guest_images[item].name }}.{{ guest_images[item].type }}
ignore_errors: true
with_items: "{{ guest_images }}"
Loading

0 comments on commit 77fb63f

Please sign in to comment.