= [https://groups.geni.net/geni/wiki/GENIExperimenter/Tutorials/AnsibleHelloGENI Converting the Hello GENI Install Script to Ansible] = {{{ #!html
Image Map
}}} == 1. Design the Experiment == In this exercise we will convert the [wiki:GENIExperimenter/Tutorials/RunHelloGENI HelloGENI exercise] install script into an Ansible playbook. You may want to quickly run the [wiki:GENIExperimenter/Tutorials/RunHelloGENI HelloGENI exercise] to see how it works. {{{ #!div style="background: #fdd; border: 3px ridge; width: 800px;" For reference here is the install script pruned to only handle Apache 2.2 (the original handles multiple versions of Apache). {{{ #!sh #!/bin/bash #---------------------------------------------------------------------- # Copyright (c) 2012-2017 Raytheon BBN Technologies # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and/or hardware specification (the "Work") to # deal in the Work without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Work, and to permit persons to whom the Work # is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Work. # # THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS # IN THE WORK. #---------------------------------------------------------------------- # Usual directory for downloading software in ProtoGENI hosts is `/local` cd /local #Get the hostname to see if we are at the server or the client hn=`echo $HOSTNAME | cut -d'.' -f 1` ##### Check if file is there ##### if [ ! -f "./installed.txt" ] then #### Create the file #### sh -i -c `sudo touch "./installed.txt"` #### Run one-time commands #### #Install necessary packages sudo apt-get update sudo apt-get -y install apache2 iperf & EPID=$! wait $EPID # Install custom software ## Customize apache installation ## Reboot the host if needed fi ##### Run Boot-time commands # Start services # If this is the server then start the iperf and configure and start the http server if [ $hn == "server" ] then # Enable web server stats sudo /usr/sbin/a2enmod status sudo rm /etc/apache2/mods-enabled/status.conf echo "" | sudo tee -a /etc/apache2/sites-available/default > /dev/null echo " SetHandler server-status" |sudo tee -a /etc/apache2/sites-available/default > /dev/null echo " Allow from all" | sudo tee -a /etc/apache2/sites-available/default > /dev/null echo "" | sudo tee -a /etc/apache2/sites-available/default > /dev/null echo "ExtendedStatus On" | sudo tee -a /etc/apache2/conf.d/extendedstatus > /dev/null # Copy the website under /var/www/ sudo cp -R ./website/* /var/www/ sudo rm -rf /var/www/html sudo ln -s /var/www/ /var/www/html # Start the webserver sudo /usr/sbin/apache2ctl restart sudo service apache2 restart # Start the iperf server sudo mkdir -p /var/www/iperflogs iperf_server_log="/var/www/iperflogs/iperf-server.log" sudo bash -c "iperf -s -i 10 &> $iperf_server_log" else # If this is the client start the script for transfers # Wait 60 seconds just to give some time to the server to come up sleep 60 ./scripts/client-wget.sh& ./scripts/client-iperf.sh& fi # Start my service -- assume it was installed at /usr/local/bin }}} }}} == 2. Establish the Environment == a. To run this exercise, you will need an account and two pieces of software. If you haven't already, get or install these now: i. a GENI Portal account ([SignMeUp instructions]), ii. `omni` installed and configured on your local machine ([https://github.com/GENI-NSF/geni-tools/wiki#getting-started instructions]), and iii. `ansible` installed on your local machine ([http://docs.ansible.com/intro_installation.html#latest-release-via-yum find the instructions for your package manager here]). {{{ #!div style="background: #fdd; border: 3px ridge; width: 800px;" Windows users should do the following steps {{{ #!html
Tip Windows users should follow the instructions for setting up a separate GENI node for running Ansible.
}}} }}} a. Download the webpages and scripts needed for the HelloGENI exercise. {{{ #!div style="background: #ffd; border: 3px ridge; width: 800px;" Use `wget` to download the tarball of files onto your local machine and use `tar` to uncompress it: {{{ #!sh wget https://github.com/GENI-NSF/geni-tutorials/raw/master/HelloGENI/hellogeni-install.tar.gz tar zxvf hellogeni-install.tar.gz }}} }}} == 3. Obtain Resources == a. Reserve the [https://raw.githubusercontent.com/GENI-NSF/geni-tutorials/master/AnsibleHelloGENI/ansible_request_rspec_noinstall_v2.xml] in a slice named `ansibleXX` where `XX` is your initials. ---- = [wiki:GENIExperimenter/Tutorials/AnsibleHelloGENI Introduction] = = [wiki:GENIExperimenter/Tutorials/AnsibleHelloGENI/Execute Next: Execute] =