From 1970c887d15e4111a4e93761814a163dd64bc4c0 Mon Sep 17 00:00:00 2001 From: Donovan Jones Date: Sat, 21 Oct 2017 14:45:17 +1300 Subject: [PATCH] include-vs-import cookbook --- cookbooks/imported-static-tasks.yaml | 22 ++++++++++++++++ cookbooks/include-vs-import.yaml | 36 +++++++++++++++++++++++++++ cookbooks/included-dynamic-tasks.yaml | 22 ++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 cookbooks/imported-static-tasks.yaml create mode 100644 cookbooks/include-vs-import.yaml create mode 100644 cookbooks/included-dynamic-tasks.yaml diff --git a/cookbooks/imported-static-tasks.yaml b/cookbooks/imported-static-tasks.yaml new file mode 100644 index 0000000..668a3ed --- /dev/null +++ b/cookbooks/imported-static-tasks.yaml @@ -0,0 +1,22 @@ +- name: Imported static task 1 + debug: + var: foobar + +- name: Imported static task 2 + debug: + var: foobar + +- name: Imported static task 3 + debug: + var: foobar + +- name: Imported static task 4 + debug: + var: foobar + tags: xyzzy + +- name: Imported static task 5 + debug: + var: foobar + tags: frobozz + diff --git a/cookbooks/include-vs-import.yaml b/cookbooks/include-vs-import.yaml new file mode 100644 index 0000000..590ceee --- /dev/null +++ b/cookbooks/include-vs-import.yaml @@ -0,0 +1,36 @@ +#!/usr/bin/env ansible-playbook +--- + +# https://docs.ansible.com/ansible/2.4/playbooks_reuse.html#dynamic-vs-static + +- name: Demonstrate the difference between Includes and Imports + hosts: localhost + vars: + foobar: false + + tasks: + - name: Include extra tasks dynamically + import_tasks: included-dynamic-tasks.yaml + when: foobar + + - name: Import extra tasks statically + include_tasks: imported-static-tasks.yaml + when: foobar + + # ERROR! You cannot use loops on 'import_tasks' statements. You should use 'include_tasks' instead. + - name: Include extra tasks dynamically + import_tasks: included-dynamic-tasks.yaml + + - name: Import extra tasks statically + include_tasks: imported-static-tasks.yaml + with_items: + - foo + - bar + + - name: Include extra tasks dynamically with tag xyzzy + import_tasks: included-dynamic-tasks.yaml + tags: xyzzy + + - name: Import extra tasks statically with tag xyzzy + include_tasks: imported-static-tasks.yaml + tags: xyzzy diff --git a/cookbooks/included-dynamic-tasks.yaml b/cookbooks/included-dynamic-tasks.yaml new file mode 100644 index 0000000..8b314f6 --- /dev/null +++ b/cookbooks/included-dynamic-tasks.yaml @@ -0,0 +1,22 @@ +- name: Included dynamic task 1 + debug: + var: foobar + +- name: Included dynamic task 2 + debug: + var: foobar + +- name: Included dynamic task 3 + debug: + var: foobar + +- name: Included dynamic task 4 + debug: + var: foobar + tags: xyzzy + +- name: Included dynamic task 5 + debug: + var: foobar + tags: frobozz +