= [http://groups.geni.net/geni/wiki/GENIExperimenter/Tutorials/AnsibleHelloGENI Title of the Experiment] = {{{ #!html
Image Map
}}} == 4. Configure and Initialize == `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 }}} Here example output of running these commands: {{{ #!sh $ readyToLogin ansible --useSliceAggregates --ansible-inventory -o Host info saved in inventory file: /Users/jdoe/projects/GENI/hellogeni/inventory $ cat inventory client ansible_ssh_host=pc3.instageni.clemson.edu ansible_ssh_port=33850 server ansible_ssh_host=pcvm3-6.instageni.clemson.edu }}} }}} b. 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 all -m ping -i inventory }}} Example output showing all of the nodes responding to ping: {{{ #!sh $ ansible all -m ping -i inventory client | success >> { "changed": false, "ping": "pong" } server | success >> { "changed": false, "ping": "pong" } }}} }}} c. Try using the ping module in Ansible to only ping `server` or `client` by replacing `all` in the above with `server` or `client`. == 5. Execute Experiment == {{{ #!div style="background: #ffd; border: 3px ridge; width: 800px;" {{{ #!html
Tip The following are some example Ansible Ad Hoc commands. You can run these commands one at a time from the machine where you have Ansible installed. `-s` tells Ansible to use `sudo` when executing the command.
}}} `apt` module is used to installed packages: {{{ #!sh ansible [-i inventory] [all/server/client] -s -m apt -a "name=apache2 update_cache=yes" }}} `shell` module is used to execute an arbitrary shell command: {{{ #!sh ansible [-i inventory] [all/server/client] -s -m shell -a "/usr/sbin/a2enmod status" }}} `file` module is used to manipulate files: {{{ #!sh ansible [-i inventory] [all/server/client] -s -m file -a "path=/var/www/html state=absent" }}} `synchronize` module is an implementation of `rsync` and is used to efficiently synchronize files between your local machine and the node: {{{ #!sh ansible [-i inventory] [all/server/client] -s -m synchronize \ -a "src=website/index.html dest=/var/www" }}} `lineinfile` module is used to see if an arbitrary line exists in a file: {{{ #!sh ansible [-i inventory] [all/server/client] -s -m lineinfile \ -a "line='ExtendedStatus On' dest=/etc/apache2/conf.d/extendedstatus create=yes state=present" }}} `service` module is used to start/stop/restart/etc services: {{{ #!sh ansible [-i inventory] [all/server/client] -s -m service -a "name=apache2 state=restarted" }}} }}} a. Using the above Ad Hoc Ansible commands do the following: i. on both `client` and `server`, install `apache2` and `iperf` i. on the `client` node, place the `scripts` directory in `/local` with permissions `755`. {{{ #!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 commands to configure the `client` node as in the install script are as follows: {{{ #!python --- - name: Configure client hosts: client sudo: True tasks: - name: install apache2 apt: name=apache2 update_cache=yes - name: install iperf apt: name=iperf update_cache=yes - name: copy scripts into /local with permissions 755 synchronize: src=scripts dest=/local mode=755 }}} Let's put the above in a file `hello-client.yml`. Run the playbook with the following command on the local machine: {{{ #!python ansible-playbook hello-client.yml -i inventory }}} }}} a. Using the above Ansible modules, reproduce the steps in the HelloGENI install script for the `server` node. As you find a command that works, construct a `hello-server.yml` playbook. == 6. Analyze Experiment == a. You may have noticed that the server playbook and the client playbook contained duplicate text. This is because both nodes need to have apache installed so that they can act as webservers. As you might have guessed, there is a way to modularize this configuration. In Ansible this is done with "roles". ---- = [wiki:GENIExperimenter/Tutorials/AnsibleHelloGENI Introduction/DesignSetup] = = [wiki:GENIExperimenter/Tutorials/AnsibleHelloGENI/Finish Next: Finish] =