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 | |
| 100 | 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. |
| 101 | |
| 102 | === (b) Get the container IP address === |
| 103 | |
| 104 | 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. |
| 105 | |
| 106 | === (c) Get the control host name === |
| 107 | |
| 108 | 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. |
| 109 | |
| 110 | === (d) Get the host's public IP address === |
| 111 | |
| 112 | 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>'''. |
| 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 | |
| 122 | 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'''. |
| 123 | |
| 124 | {{{ |
| 125 | $ geoiplookup -f <data file> <ip address> |
| 126 | }}} |
| 127 | |
| 128 | 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. |
| 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 | |
| 136 | At this point, you should have enough information to fetch the parameterized URL in the playbook. |
| 137 | |
| 138 | Here 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. |
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 | ---- |