Difference between import and include statements

289 views
Skip to first unread message

Nick Kakouros

unread,
Jul 19, 2017, 5:30:49 PM7/19/17
to Ansible Project
I read on the changelog for 2.4:

New import/include keywords to replace the old bare include directives. The use of static: {yes|no} on such includes is now deprecated.
  • Using import_* (import_playbook, import_tasks, import_role) directives are static.
  • Using include_* (include_tasks, include_role) directives are dynamic.
Can someone provide a use case where the one would benefit the other?

Brian Coca

unread,
Jul 19, 2017, 5:39:35 PM7/19/17
to Ansible Project
Well, there are many different behaviours, depends on what you want to
do, here is simple example:

- import_tasks: x.yml
with_items: [1,2,3]

This willi import x.yml one time and every imported task will now run
and loop over 1,2,3

- include_tasks: x.yml
with_items: [1,2,3]

This will include x.yml 3 times and set the 'item' variable to 1, 2
and 3 respectively



----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages