From b95cbeda4985e9bc8db98455311c01b97e9aa5ba Mon Sep 17 00:00:00 2001 From: akrzos Date: Sat, 27 Aug 2016 14:45:30 -0400 Subject: [PATCH] Make Browbeat multi-cloud friendly. This commit "localizes" ssh-config and heat-admin-id_rsa to your local Browbeat directory. This allows one to simply cd into the directory of the cloud they are working with Browbeat against and ensure they do not incorrectly run playbooks against the wrong hosts. Example: [akrzos@bithead ansible]$ ./generate_tripleo_hostfile.sh x.x.x.x ... [akrzos@bithead ansible]$ ls -la ... -rwxrwxr-x. 1 akrzos akrzos 9461 Aug 25 16:18 generate_tripleo_hostfile.sh -rw-------. 1 akrzos akrzos 1675 Aug 27 14:16 heat-admin-id_rsa -rw-rw-r--. 1 akrzos akrzos 338 Aug 27 14:16 hosts -rw-------. 1 akrzos akrzos 2013 Aug 27 14:16 ssh-config ... [akrzos@bithead ansible]$ ssh -F ssh-config root@undercloud [root@gprfc007 ~]# exit logout [akrzos@bithead ansible]$ ssh -F ssh-config undercloud-stack [stack@gprfc007 ~]$ exit logout [akrzos@bithead ansible]$ ssh -F ssh-config undercloud-root [root@gprfc007 ~]# exit logout [akrzos@bithead ansible]$ ssh -F ssh-config overcloud-controller-0 Warning: Permanently added '10.16.154.18' (ECDSA) to the list of known hosts. Warning: Permanently added 'overcloud-controller-0' (ECDSA) to the list of known hosts. [heat-admin@overcloud-controller-0 ~]$ exit logout [akrzos@bithead ansible]$ ssh -F ssh-config overcloud-controller-1 [heat-admin@overcloud-controller-1 ~]$ exit logout [akrzos@bithead ansible]$ ssh -F ssh-config overcloud-controller-2 [heat-admin@overcloud-controller-2 ~]$ exit logout [akrzos@bithead ansible]$ ssh -F ssh-config overcloud-novacompute-0 [heat-admin@overcloud-novacompute-0 ~]$ exit logout [akrzos@bithead ansible]$ ansible-playbook -i hosts install/collectd-openstack.yml ... Tested against the collectd-openstack and grafana-dashboards playbooks Potential issues: CI? (Does CI execute any playbooks from the ansible directory? If so we shouldn't have an issue here.) lib/{ansible/adjustments} - Can we make sure to pass the either the correct ssh-config or use the ansible.cfg inside ansible/? Change-Id: I4764490e5164f7d4d896cbe5bd26e6a59d770df4 --- .gitignore | 4 ++++ README.rst | 24 +++++++++++++++++-- ansible/ansible.cfg | 4 ++++ ansible/generate_tripleo_hostfile.sh | 12 +++++----- ansible/install/roles/browbeat/tasks/main.yml | 12 ++++++---- 5 files changed, 44 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 39f94a42a..d48275180 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,10 @@ # Ansible files *.retry +# Prevent ssh files from sneaking into the git repo +ansible/ssh-config +ansible/heat-admin-id_rsa + # Prevent hosts files from sneaking into the git repo ansible/hosts diff --git a/README.rst b/README.rst index 472da5fa4..38b73d179 100644 --- a/README.rst +++ b/README.rst @@ -31,6 +31,7 @@ Table of Contents browbeat <#run-performance-stress-tests-through-browbeat>`__ - `Running PerfKitBenchmarker <#running-perfkitbenchmarker>`__ +- `Working with Multiple Clouds <#working-with-multiple-clouds>`__ - `Contributing <#contributing>`__ - `Adding Functionality <#adding-functionality>`__ @@ -94,7 +95,7 @@ From your local machine $ ssh-copy-id stack@ $ git clone https://github.com/openstack/browbeat.git $ cd browbeat/ansible - $ ./generate_tripleo_hostfile.sh ~/.ssh/config + $ ./generate_tripleo_hostfile.sh $ vi install/group_vars/all.yml # Make sure to edit the dns_server to the correct ip address $ ansible-playbook -i hosts install/browbeat.yml $ vi install/group_vars/all.yml # Edit browbeat network settings @@ -158,7 +159,7 @@ From your undercloud [root@ospd ~]# su - stack [stack@ospd ~]$ git clone https://github.com/openstack/browbeat.git [stack@ospd ~]$ cd browbeat/ansible - [stack@ospd ansible]$ ./generate_tripleo_hostfile.sh localhost ~/.ssh/config + [stack@ospd ansible]$ ./generate_tripleo_hostfile.sh localhost [stack@ospd ansible]$ sudo easy_install pip [stack@ospd ansible]$ sudo pip install ansible [stack@ospd ansible]$ vi install/group_vars/all.yml # Make sure to edit the dns_server to the correct ip address @@ -238,6 +239,25 @@ browbeat-config.yaml: (browbeat-venv)[stack@ospd browbeat]$ ./browbeat.py perfkit -s browbeat-config.yaml +Working with Multiple Clouds +============================ + +If you are running playbooks from your local machine you can run against more +than one cloud at the same time. To do this, you should create a directory +per-cloud and clone browbeat into that specific directory: + +:: + + [browbeat@laptop ~]$ mkdir cloud01; cd cloud01 + [browbeat@laptop cloud01]$ git clone git@github.com:openstack/browbeat.git + ... + [browbeat@laptop cloud01]$ cd browbeat/ansible + [browbeat@laptop ansible]$ ./generate_tripleo_hostfile.sh + [browbeat@laptop ansible]$ ansible-playbook -i hosts (Your playbook you wish to run...) + [browbeat@laptop ansible]$ ssh -F ssh-config overcloud-controller-0 # Takes you to first controller + +Repeat the above steps for as many clouds as you have to run playbooks against your clouds. + Contributing ============ diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg index 85481a152..5f4138eff 100644 --- a/ansible/ansible.cfg +++ b/ansible/ansible.cfg @@ -3,3 +3,7 @@ gathering = smart fact_caching_timeout = 86400 fact_caching = jsonfile fact_caching_connection = /tmp/browbeat_fact_cache + +[ssh_connection] +# Load the specific ssh config file in this directory +ssh_args = -F ssh-config diff --git a/ansible/generate_tripleo_hostfile.sh b/ansible/generate_tripleo_hostfile.sh index 099df86e4..9a8864150 100755 --- a/ansible/generate_tripleo_hostfile.sh +++ b/ansible/generate_tripleo_hostfile.sh @@ -1,12 +1,12 @@ #!/bin/bash -if [ ! $# -ge 2 ]; then - echo "Usage: ./generate_tripleo_hostfiles.sh " +if [ ! $# -ge 1 ]; then + echo "Usage: ./generate_tripleo_hostfiles.sh " echo "Generates ssh config file to use with an TripleO undercloud host as a jumpbox and creates ansible inventory file." exit fi tripleo_ip_address=$1 ansible_inventory_file='hosts' -ssh_config_file=$2 +ssh_config_file='ssh-config' # "Hackish" copy ssh key to self if we are on directly on the undercloud machine: if [[ "${tripleo_ip_address}" == "localhost" ]]; then @@ -107,9 +107,9 @@ for line in $nodes; do fi echo "" | tee -a ${ssh_config_file} echo "Host ${host}" | tee -a ${ssh_config_file} - echo " ProxyCommand ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=60 -i ~/.ssh/id_rsa undercloud-stack -W ${IP}:22" | tee -a ${ssh_config_file} + echo " ProxyCommand ssh -F ssh-config -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=60 -i ~/.ssh/id_rsa stack@${tripleo_ip_address} -W ${IP}:22" | tee -a ${ssh_config_file} echo " User heat-admin" | tee -a ${ssh_config_file} - echo " IdentityFile ~/.ssh/heat-admin-id_rsa" | tee -a ${ssh_config_file} + echo " IdentityFile heat-admin-id_rsa" | tee -a ${ssh_config_file} echo " StrictHostKeyChecking no" | tee -a ${ssh_config_file} echo " UserKnownHostsFile=/dev/null" | tee -a ${ssh_config_file} done @@ -180,4 +180,4 @@ echo "---------------------------" echo "Copying heat-admin key to local machine(~/.ssh/heat-admin-id_rsa) to for use with ssh config file" echo "---------------------------" echo "" -scp -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" "stack@${tripleo_ip_address}":/home/stack/.ssh/id_rsa ~/.ssh/heat-admin-id_rsa +scp -o "UserKnownHostsFile /dev/null" -o "StrictHostKeyChecking no" "stack@${tripleo_ip_address}":/home/stack/.ssh/id_rsa heat-admin-id_rsa diff --git a/ansible/install/roles/browbeat/tasks/main.yml b/ansible/install/roles/browbeat/tasks/main.yml index f3637191e..dcb1e4622 100644 --- a/ansible/install/roles/browbeat/tasks/main.yml +++ b/ansible/install/roles/browbeat/tasks/main.yml @@ -81,12 +81,16 @@ git: repo=https://github.com/openstack/browbeat.git dest={{ browbeat_path }} version=master when: browbeat_exists.stat.isdir is undefined -- name: Generate hosts and ~/.ssh/config on undercloud - shell: . {{ home_dir }}/stackrc; {{ browbeat_path }}/ansible/generate_tripleo_hostfile.sh localhost {{ home_dir }}/.ssh/config +- name: Generate hosts and ssh-config on undercloud + shell: . {{ home_dir }}/stackrc; {{ browbeat_path }}/ansible/generate_tripleo_hostfile.sh localhost when: tripleo -- name: Move hosts file to correct location - command: mv {{ home_dir }}/hosts {{ browbeat_path }}/ansible/hosts +- name: Move files to correct location + command: mv {{ home_dir }}/{{item}} {{ browbeat_path }}/ansible/{{item}} + with_items: + - hosts + - ssh-config + - heat-admin-id_rsa - name: Install requirements.txt into browbeat-venv pip: requirements={{ browbeat_path }}/requirements.txt virtualenv={{ browbeat_venv }}