= [.. Systematic Experimentation (with Ansible)] = {{{ #!html
Image Map
}}} == 4. Configure and Initialize == === 4.1. Download the Ansible playbook === a. Download the Ansible playbook, webpages, etc needed to configure the nodes. {{{ #!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 mkdir ansible cd ansible wget https://github.com/GENI-NSF/geni-tutorials/raw/master/ansible/ansible.tar.gz tar zxvf ansible.tar.gz }}} }}} === 4.2. Create the Ansible inventory file === `omni` comes with a script, `readyToLogin` which finds the login information for nodes in your slice. As of `omni` version 2.8, `readyToLogin` has an `--ansible-inventory` flag which generates the Ansible inventory, which is a flat file which tells Ansible the name and login information for your nodes. a. Create your Ansible inventory file: {{{ #!div style="background: #ffd; border: 3px ridge; width: 800px;" On your local machine: {{{ #!sh $ readyToLogin MYSLICE --useSliceAggregates --ansible-inventory -o $ cat inventory }}} Example output of running these commands: {{{ #!sh $ readyToLogin MYSLICE --useSliceAggregates --ansible-inventory -o Host info saved in inventory file: /Users/jdoe/projects/GENI/hellogeni/inventory $ cat inventory host-2 ansible_ssh_host=pc2.instageni.stanford.edu ansible_ssh_port=31291 host-1 ansible_ssh_host=pc2.instageni.stanford.edu ansible_ssh_port=31290 server-1 ansible_ssh_host=pcvm2-33.instageni.stanford.edu rt-1 ansible_ssh_host=pc2.instageni.stanford.edu ansible_ssh_port=31292 }}} }}} {{{ #!div style="background: #fdd; border: 3px ridge; width: 800px;" {{{ #!html
Tip Windows users should copy their 'inventory' file onto their node running the ansible client.
}}} }}} b. Be sure your private key has been added to your SSH agent: {{{ #!div style="background: #ffd; border: 3px ridge; width: 800px;" {{{ ssh-add /path/to/your/private/key }}} Example output of running these commands: {{{ #!sh $ ssh-add /home/lnevers/.ssh/geni_cert_portal_key Identity added: /home/lnevers/.ssh/geni_cert_portal_key (/home/lnevers/.ssh/geni_cert_portal_key) }}} }}} c. Check to see if your nodes are up and ready. {{{ #!div style="background: #ffd; border: 3px ridge; width: 800px;" This command uses the `ping` module to ping the specified nodes (in this case `all`) listed in the inventory file: {{{ #!sh $ ansible -i inventory all -m ping }}} Example output showing all of the nodes responding to ping: {{{ #!sh $ ansible -i inventory all -m ping server-1 | success >> { "changed": false, "ping": "pong" } host-1 | success >> { "changed": false, "ping": "pong" } rt-1 | success >> { "changed": false, "ping": "pong" } host-2 | success >> { "changed": false, "ping": "pong" } }}} }}} c. Try using the ping module in Ansible to only ping `server-1` or `host-1` by replacing `all` in the above with `server-1` or `host-1`. === 4.3. Configure the nodes === {{{ #!div style="background: #ffd; border: 3px ridge; width: 800px;" {{{ #!html
Tip Ansible commands can be collected into files called Playbooks. Playbooks are in a configuration file format called YAML which is very straightforward. In particular, Ansible Ad Hoc commands easily map to commands used in an Ansible Playbook.
}}} The Playbook to configure the `server` node is in `server.yml`. It links to other files. For example, the code to tell the `server` node to run an `nmap` scan and post the results is in `roles/nmap/tasks/map.yml` and looks as follows: {{{ #!python --- - name: map network using nmap command: nmap -sP -oX {{ nmap_xml_file }} {{ address_range }} - name: convert nmap xml to html shell: xsltproc /usr/share/nmap/nmap.xsl {{ nmap_xml_file }} > {{ nmap_html_file }} - name: create directory for nmap logs in WEB_ROOT/nmaplogs with permissions of 755 file: > dest={{ WEB_ROOT }}/{{ nmap_dir }} state=directory mode=755 - name: copy nmap html file to a public place command: mv {{ nmap_html_file }} {{ WEB_ROOT }}/{{ nmap_dir }}/nmap.html removes={{ nmap_html_file }} }}} }}} a. Edit the file `group_vars/all.yml` so that the `address_range` variable uses the IP subnet from your topology. It should look like this: {{{ #!python address_range: 10.10.1.1-10 }}} a. Run the playbook to configure the `server` with the following command on the local machine: {{{ #!python ansible-playbook server.yml -i inventory --limit server }}} a. Browse to hostname of the server node in your browser. Click on the `nmap` link. a. If this looks ok, run the following to install the code on both of your servers: {{{ #!python ansible-playbook server.yml -i inventory }}} a. Browse to the hostname of the `server-0` node in your browser. === 4.4. Update a portion of the configuration === a. Run the following command to only update the `nmap` portion of the `server` configuration: {{{ #!python ansible-playbook update-map.yml -i inventory }}} a. Feel free to change the value of `address_range` in `groups_vars/all.yml` and rerun `update-map.yml` to search for different nodes. == 5. Execute Experiment == For a real experiment, you would now run your procedure. ---- = [wiki:GENIExperimenter/Tutorials/SystematicExperimentationAnsible/Design Setup] = = [wiki:GENIExperimenter/Tutorials/SystematicExperimentationAnsible/Finish Next: Finish] =