50 | | == 3. Learn basic concepts of Ansible == |
| 50 | == 3. Configure the Ansible controller for your slicelet == |
| 51 | |
| 52 | If you already have Ansible installed on your laptop, then you can use it as the controller for this experiment. Otherwise, you will use one of the nodes in your slicelet as the Ansible controller. Pick one, log into it, and install ansible using apt-get: |
| 53 | |
| 54 | {{{ |
| 55 | $ apt-get update |
| 56 | $ apt-get install ansible |
| 57 | }}} |
| 58 | |
| 59 | Then upload your slicelet helper files to that node. {{{scp}}} can be used for this |
| 60 | |
| 61 | {{{ |
| 62 | $ scp -i id_rsa -F ssh-config ansible-hosts slice323.pcvm3-1.instageni.metrodatacenter.com:. |
| 63 | $ scp -i id_rsa -F ssh-config id_rsa slice323.pcvm3-1.instageni.metrodatacenter.com:. |
| 64 | }}} |
| 65 | |
| 66 | || [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' remove your controller node from the '''ansible_hosts''' file after you’ve uploaded. || |
| 67 | |
| 68 | ---- |
| 69 | |
| 70 | == 4. Learn some basic concepts of Ansible == |
95 | | || [[Image(wiki:GENIExperimenter/Tutorials/Graphics:tip.png, nolink, 50px, bottom)]] || '''Pro Tip:''' remove your controller node from the '''ansible_hosts''' file after you’ve uploaded. || |
| 117 | You can replace ''hostname'' above with any other Linux command. |
| 118 | |
| 119 | === (c) The setup module === |
| 120 | |
| 121 | The '''setup''' module gathers a bunch of information about each node and saves it in variables that you can reference in your Ansible playbooks. This will be really useful to do the tutorial! Try it out on a node to see what it collects (replace `<your-slicelet>` with your slicelet’s name): |
| 122 | |
| 123 | {{{ |
| 124 | $ ansible <your-slicelet>.pcvm1-1.instageni.wisc.edu -i ansible-hosts -m setup |
| 125 | }}} |
| 126 | |
| 127 | === (d) A simple playbook === |
| 128 | |
| 129 | Next, 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: |
| 130 | |
| 131 | {{{ |
| 132 | #!python |
| 133 | --- |
| 134 | - hosts: nodes |
| 135 | remote_user: root |
| 136 | tasks: |
| 137 | - name: An example of a debug statement |
| 138 | debug: var=ansible_hostname |
| 139 | }}} |
| 140 | |
| 141 | Run the playbook as: |
| 142 | |
| 143 | {{{ |
| 144 | $ ansible-playbook -i ansible-hosts test.yaml |
| 145 | }}} |
| 146 | |
| 147 | The '''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). |
| 148 | |