Changes between Version 8 and Version 9 of GENIExperimenter/Tutorials/GENIExperimentEngine/Execute


Ignore:
Timestamp:
03/11/15 16:30:14 (9 years ago)
Author:
acb@cs.princeton.edu
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GENIExperimenter/Tutorials/GENIExperimentEngine/Execute

    v8 v9  
    3232== 1. Experiment with various Ansible modules: ping, shell, setup ==
    3333
    34 We will first get familiar with some basic Ansible commands using the command-line interface.  The '''ping''' module simply tries to do a SSH login to a node and reports success or failure.  Run the following command on your controller:
     34We will first get familiar with some basic Ansible commands using the command-line interface. 
     35
     36=== 1.1 The ping module ===
     37
     38The '''ping''' module simply tries to do a SSH login to a node and reports success or failure.  Run the following command on your controller:
    3539
    3640{{{
     
    3943
    4044If you don’t see success everywhere then there is something wrong with your setup.  Ask one of the tutorial leaders for help.
     45
     46=== 1.2 The shell module ===
    4147
    4248The '''shell''' module lets you run arbitrary SSH commands in parallel across a set of hosts.  It’s useful for poking around, or if there is no Ansible module with the functionality you need.  Try it out:
     
    4854You can replace ''hostname'' above with any other Linux command.
    4955
     56=== 1.3 The setup module ===
     57
    5058The '''setup''' module gathers a bunch of information about each node and saves it in variables that you can reference in your Ansible playbooks.  This will be really useful to do the tutorial!   Try it out on a node to see what it collects (replace slice338 with your slicelet’s name):
    5159
     
    5664== 2. Create an Ansible playbook to download a parameterized URL from each node ==
    5765
    58 First create a starter Ansible playbook.  Recall that a playbook is a YAML file containing a list of Ansible commands.  Copy the following into a file called lab.yaml:
     66=== 2.1 Create a starter Ansible playbook ===
     67
     68A playbook is a YAML file containing a list of Ansible commands.  To get started creating your Ansible playbook, copy the following into a file called lab.yaml:
    5969
    6070{{{
     
    7484The '''setup''' module is run automatically at the beginning of a playbook to populate variables for each node.  The above playbook will dump the value of each node’s ''ansible_hostname'' variable.  To run the playbook on a single node, replace ''nodes'' with the name of one of your slice nodes (e.g., slice338.pcvm3-7.instageni.nps.edu).
    7585
     86=== 2.2 Iteratively build your Ansible playbook ===
     87
     88Now, think about how you are going to solve the problems of this tutorial.  You need to collect several pieces of information on each node: the container name, the IP of the host (i.e., the VM hosting the container), the IP of the container, and the latitude and longitude of the host.  You then need to fetch a custom URL containing this information from each host.
     89
    7690|| [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' Solve the problem on one node in your slice first, then deploy your solution to the remaining nodes.  One thing at a time. ||
    7791
    78 Now, think about how you are going to solve the problems of this tutorial. 
     92|| [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' Build your solution a piece at a time.  Each step is, basically: (1) run a command, (2) possibly extract the information from the output and register it in an Ansible variable ||
    7993
    80 For instance, the IP address visible inside the slicelet (as reported in the variable ''ansible_eth0.ipv4.address'') is a private address -- it is not the control address of the host, which is one piece of information you want.  There are a number of ways that you could discover the control address, including running '''dig +short''' on the host’s name (see if you can find a variable that contains this; HINT: you need it to SSH into the slicelet) or by running '''curl''' against a webserver that reports the client’s externally visible address.
     94For instance, how to get the host's IP address? The IP address visible inside the slicelet (as reported in the variable ''ansible_eth0.ipv4.address'') is a private address -- it is not the control address of the host.  There are a number of ways that you could discover the control address, including running '''dig +short''' on the host’s name (see if you can find a variable that contains this; HINT: you need it to SSH into the slicelet) or by running '''curl''' against a webserver that reports the client’s externally visible address.
     95
     96|| [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' The '''ansible''' command-line tool is a good way to try out Ansible commands before putting them in your playbook. ||
     97
     98|| [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' Usually in an Ansible playbook you reference a variable by surrounding it in double curly brackets: ''{{ ansible_eth0.ipv4.address }}'' ||
     99
     100|| [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' When you run an Ansible command in a playbook, you can save the output into a new variable using '''register: varname'''  Then you can retrieve the value later in the playbook using ''{{ varname }}'' or, for shell command output, ''{{ varname.stdout }}'' ||
    81101
    82102Another requirement of the lab is to map the control IP address obtained above to the latitude and longitude for each node.  For instance you can use the '''geoiplookup''' tool, provided by package '''geoip-bin'''.
     
    89109A different approach would be to run '''curl''' against a webserver that maps IP address to latitude and longitude, such as http://ipinfo.io, and parse the output.  '''NOTE:''' this particular website rate-limits the number of requests per node per day, so if you use it, ''make only a single request per node and save the result in a file''… keep in mind that everyone in the tutorial may be hitting this server from the same set of hosts!
    90110
    91 || [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' Usually in an Ansible playbook you reference a variable by surrounding it in double curly brackets: ''{{ ansible_eth0.ipv4.address }}'' ||
    92 
    93 || [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' When you run an Ansible command in a playbook, you can save the output into a new variable using '''register: varname'''  Then you can retrieve the value later in the playbook using ''{{ varname }}'' or, for shell command output, ''{{ varname.stdout }}'' ||
    94 
    95111|| [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' The Ansible '''script''' module can be used to run arbitrary scripts in your slicelet.  See: http://docs.ansible.com/script_module.html ||
    96112
    97 || [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' Not all the resources you may need are installed on the nodes!  Part of this tutorial is learning how to install software and configure a node to do what you want.  Step one is to figure out what you need, what you have, and then how to get the rest.  The command which will tell you if something’s installed.  The '''apt''' Ansible module is useful for installing packages; see: http://docs.ansible.com/apt_module.html ||
     113|| [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' Not all the resources you may need are installed on the nodes!  The '''apt''' Ansible module is useful for installing packages; see: http://docs.ansible.com/apt_module.html ||
    98114
    99 || [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' Build your solution a piece at a time.  Each step is, basically: (1) run a command, (2) possibly extract the information from the output and register it in an Ansible variable ||
    100115
    101116At this point, you can flesh out base Ansible playbook to complete the lab.  No need to hurry.  Run the command, look at the output; use Ansible’s debug module to print the value of the variable you’re stuffing it into.  Getting the information may involve a sequence of text-processing steps (get the right line, strip off trailing stuff, strip off leading stuff, etc).  So, do each step, one at a time, and print out the value after each step.  This will help you find errors quickly and get to something working very quickly.