81 | | A 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! |
| 81 | A 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! |
| 82 | |
| 83 | '''Pro Tip:''' Usually in an Ansible playbook you reference a variable by surrounding it in double curly brackets: ''{{ ansible_eth0.ipv4.address }}'' |
| 84 | |
| 85 | '''Pro Tip #2:''' 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 |
| 86 | ''{{ varname }}'' or, for shell command output, ''{{ varname.stdout }}'' |
| 87 | |
| 88 | '''Pro Tip #3:''' The Ansible '''script''' module can be used to run arbitrary scripts in your slicelet. See: http://docs.ansible.com/script_module.html |
| 89 | |
| 90 | '''Pro Tip #4:''' 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 |
| 91 | |
| 92 | '''Pro Tip #5:''' Build your solution a piece at a time. Each step is, basically: |
| 93 | - run a command |
| 94 | - possibly extract the information from the output and register it in an Ansible variable |
| 95 | |
| 96 | 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. |