From 1d6a128100b18ebd1c5b3b785d60eb19f059bec1 Mon Sep 17 00:00:00 2001 From: Jedrzej Nowak Date: Tue, 1 Dec 2015 13:13:00 +0100 Subject: [PATCH] Added some ansible handler descripton to docs --- docs/index.rst | 1 + docs/source/handler_ansible.rst | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 docs/source/handler_ansible.rst diff --git a/docs/index.rst b/docs/index.rst index 99f1b851..3f31f801 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,6 +14,7 @@ Contents: source/glossary source/resource source/orchestration + source/handler_ansible source/examples source/deployment_plan diff --git a/docs/source/handler_ansible.rst b/docs/source/handler_ansible.rst new file mode 100644 index 00000000..895e2521 --- /dev/null +++ b/docs/source/handler_ansible.rst @@ -0,0 +1,48 @@ +.. _handler_ansible_details: + +Ansible Handler +=============== + +Let's look into simple ``hosts_file/actions/run.yaml`` example :: + + - hosts: [{{host}}] + sudo: yes + tasks: + {% for val in hosts %} + - name: Create hosts entries for {{val['name']}} => {{val['ip']}} + lineinfile: + dest: /etc/hosts + regexp: ".*{{val['name']}}$" + line: "{{val['ip']}} {{val['name']}}" + state: present + {% endfor %} + +It's pretty much standard ansible playbook, but it is processed with jinja2 before ansible is executed. + +Solar will create proper inventory :: + + localhost ansible_connection=local user=vagrant location_id="d6255f99dda2fca55177ffad96f390a9" transports_id="2db90247d5d94732448ebc5fdcc9f80d" hosts="[{'ip': u'10.0.0.4', 'name': u'node1'}, {'ip': u'10.0.0.3', 'name': u'node0'}]" + +Playbook will be also created :: + + - hosts: [localhost] + sudo: yes + tasks: + + - name: Create hosts entries for node1 => 10.0.0.4 + lineinfile: + dest: /etc/hosts + regexp: ".*node1$" + line: "10.0.0.4 node1" + state: present + + - name: Create hosts entries for node0 => 10.0.0.3 + lineinfile: + dest: /etc/hosts + regexp: ".*node0$" + line: "10.0.0.3 node0" + state: present + +You may wonder about ``hosts: [{{host}}]``, we have our own :ref:`res-transports-term` so we execute ansible like this :: + + ansible-playbook --module-path /tmp/library -i /tmp/tmpkV0U5F/tmpGmLGEwhosts_file2/inventory /tmp/tmpkV0U5F/tmpGmLGEwhosts_file2/runlNjnI3