Navigation Menu

Skip to content

Commit

Permalink
include-vs-import cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
donovan committed Oct 21, 2017
1 parent b1da4fa commit 1970c88
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 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

36 changes: 36 additions & 0 deletions 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
22 changes: 22 additions & 0 deletions 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

0 comments on commit 1970c88

Please sign in to comment.