Changes between Version 28 and Version 29 of GENIExperimenter/Tutorials/GENIExperimentEngine/Execute


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

--

Legend:

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

    v28 v29  
    3232----
    3333
    34 == 1. Experiment with various Ansible modules: ping, shell, setup ==
     34== 1. Experiment with Ansible ==
    3535
    3636We will first get familiar with some basic Ansible tasks using the command-line interface. 
     
    6666=== (d) A simple playbook ===
    6767
    68 An Ansible playbook is a YAML file containing a list of Ansible tasks.  Here is a simple playbook; copy it into a file called test.yaml:
     68Next, we will look at a simple Ansible playbook.  An Ansible playbook is a YAML file containing a list of Ansible tasks.  Copy the playbook below into a file called test.yaml:
    6969
    7070{{{
     
    8686The '''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).
    8787
     88-----
    8889
    8990== 2. Create an Ansible playbook to download a parameterized URL from each node ==
     
    9596|| [[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 ||
    9697
    97 Here is an Ansible playbook skeleton that you will use to complete the tutorial.  Copy it to a file and fill in the bits marked `# INSERT ARGUMENTS HERE` based on the instructions in the following subsections.
     98=== (a) Get the container's FQDN ===
     99
     100Look at the variables collected by Ansible's setup module (step 1(c) above).  Find one that holds the container's fully-qualified domain name (e.g., slice347.pcvm1-1.instageni.iu.edu) and dump it using a '''debug''' task. 
     101
     102=== (b) Get the container IP address ===
     103
     104Look at the variables collected by Ansible's setup module (step 1(c) above).  Find one that holds the container IP address and dump it using a '''debug''' task.
     105
     106=== (c) Get the control host name ===
     107
     108Look at the variables collected by Ansible's setup module (step 1(c) above).  Find one that holds the control host's FQDN (HINT: it begins with ''pcvm'') and dump it using a '''debug''' task.
     109
     110=== (d) Get the host's public IP address ===
     111
     112The 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.  To discover the ''public'' IP address of the node, run '''dig +short <control host name>'''.
     113
     114|| [[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 tasks before putting them in your playbook.  Look at the examples in part 1 above. ||
     115
     116|| [[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 }}''.  You can see examples of how variables are referenced in tasks in [https://github.com/ansible/ansible-examples/blob/master/language_features/get_url.yml this playbook]. ||
     117
     118|| [[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 }}''.  You can see an example of how to register a variable in [https://github.com/ansible/ansible-examples/blob/master/language_features/register_logic.yml this playbook]. ||
     119
     120=== (e) Get the latitude and longitude for each node ===
     121
     122To map the host's control IP address obtained in the previous step to the latitude and longitude for each node, use the '''geoiplookup''' tool, provided by package '''geoip-bin'''.
     123
     124{{{
     125$ geoiplookup -f <data file> <ip address>
     126}}}
     127
     128where ''<data file>'' is the database of IP addresses and locations.  You can find a good one at: http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz, which you’ll have to download to each node and unzip.   
     129
     130|| [[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 ||
     131
     132|| [[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 ||
     133
     134=== (f) Fetch the parameterized URL ===
     135
     136At this point, you should have enough information to fetch the parameterized URL in the playbook.
     137
     138Here is an Ansible playbook skeleton that you will use to complete the tutorial.  Copy it to a file name ''gee-tutorial.yaml'' and fill in the bits marked `# INSERT ARGUMENTS HERE` based on the instructions in the following subsections.
    98139
    99140{{{
     
    109150    shell: apt-get -y install python-apt
    110151
    111   - name: 2(a): Dump container FQDN
     152
     153  ### 2(a): Get the container's FQDN ###
     154  - name: Dump container FQDN
    112155    debug: # INSERT ARGUMENTS HERE
    113156
    114   - name: 2(b): Dump container IP address
     157
     158  ### 2(b):  Get the container IP address ###
     159  - name: Dump container IP address
    115160    debug: # INSERT ARGUMENTS HERE
    116161
    117   - name: 2(c): Dump control host name
     162
     163  ### 2(c): Get the control host name ###
     164  - name: Dump control host name
    118165    debug: # INSERT ARGUMENTS HERE
    119166
    120   - name: 2(d): Install dnsutils (for dig)
     167
     168  ### 2(d): Get the host's public IP address ###
     169  - name: Install dnsutils (for dig)
    121170    apt: # INSERT ARGUMENTS HERE
    122171
    123   - name: 2(d): Get my public IP using 'dig +short'
     172  - name: Get my public IP using 'dig +short'
    124173    shell: # INSERT ARGUMENTS HERE
    125174    register: public_ip
    126175
    127   - name: 2(d): Dump public_ip variable
     176  - name: Dump public_ip variable
    128177    debug: var=public_ip
    129178
    130   - name: 2(e): Install geoip-bin (for geoiplookup)
     179
     180  ### 2(e): Get the latitude and longitude for each node ###
     181  - name: Install geoip-bin (for geoiplookup)
    131182    apt: # INSERT ARGUMENTS HERE
    132183
    133   - name: 2(e): Download GeoLiteCity DB
     184  - name: Download GeoLiteCity DB
    134185    get_url: # INSERT ARGUMENTS HERE
    135186
    136   - name: 2(e): Unzip GeoLiteCity.dat.gz
     187  - name: Unzip GeoLiteCity.dat.gz
    137188    shell: gunzip -f GeoLiteCity.dat.gz
    138189
    139   - name: 2(e): Run geoiplookup to get latitude
     190  - name: Run geoiplookup to get latitude
    140191    shell: # INSERT ARGUMENTS HERE
    141192    register: latitude
    142193
    143   - name: 2(e): Dump latitude variable
     194  - name: Dump latitude variable
    144195    debug: var=latitude
    145196
    146   - name: 2(e): Run geoiplookup to get longitude
     197  - name: Run geoiplookup to get longitude
    147198    shell: # INSERT ARGUMENTS HERE
    148199    register: longitude
    149200
    150   - name: 2(e): Dump longitude variable
     201  - name: Dump longitude variable
    151202    debug: var=longitude
    152203
     204
     205  ### 2(f): Fetch the parameterized URL ###
    153206  - name: Dump the full URL
    154207  - debug: msg="http://www.lively-web.org/nodejs/GEETutorial/helloWorld?slice=# INSERT ARGUMENTS HERE"
     
    157210}}}
    158211
    159 
    160 
    161 === (a) Get the container's FQDN ===
    162 
    163 Look at the variables collected by Ansible's setup module (step 1(c) above).  Find one that holds the container's fully-qualified domain name (e.g., slice347.pcvm1-1.instageni.iu.edu) and dump it using a '''debug''' task. 
    164 
    165 === (b) Get the container IP address ===
    166 
    167 Look at the variables collected by Ansible's setup module (step 1(c) above).  Find one that holds the container IP address and dump it using a '''debug''' task.
    168 
    169 === (c) Get the control host name ===
    170 
    171 Look at the variables collected by Ansible's setup module (step 1(c) above).  Find one that holds the control host's FQDN (HINT: it begins with ''pcvm'') and dump it using a '''debug''' task.
    172 
    173 === (d) Get the host's public IP address ===
    174 
    175 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.  To discover the ''public'' IP address of the node, run '''dig +short <control host name>'''.
    176 
    177 || [[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 tasks before putting them in your playbook.  Look at the examples in part 1 above. ||
    178 
    179 || [[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 }}''.  You can see examples of how variables are referenced in tasks in [https://github.com/ansible/ansible-examples/blob/master/language_features/get_url.yml this playbook]. ||
    180 
    181 || [[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 }}''.  You can see an example of how to register a variable in [https://github.com/ansible/ansible-examples/blob/master/language_features/register_logic.yml this playbook]. ||
    182 
    183 === (d) Get the latitude and longitude for each node ===
    184 
    185 To map the host's control IP address obtained in the previous step to the latitude and longitude for each node, use the '''geoiplookup''' tool, provided by package '''geoip-bin'''.
    186 
    187 {{{
    188 $ geoiplookup -f <data file> <ip address>
    189 }}}
    190 
    191 where ''<data file>'' is the database of IP addresses and locations.  You can find a good one at: http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz, which you’ll have to download to each node and unzip.   
    192 
    193 || [[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 ||
    194 
    195 || [[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 ||
    196 
    197 At this point, you should have enough information to fetch the parameterized URL in the playbook.
     212----
    198213
    199214== 3. Run the playbook ==
     
    203218As a data point, our Ansible playbook contained six commands (not including debug commands) and used the '''apt''', '''shell''', and '''get_url''' modules.
    204219
     220----
     221
    205222== 4. Verify that your playbook worked as expected ==
    206223
     
    211228You should see an entry for each node in your slicelet.
    212229
     230----
     231
    213232= [wiki:GENIExperimenter/Tutorials/GENIExperimentEngine/Finish Next: Teardown Experiment] =