What's really the purpose of pre_tasks and post_tasks?

69 views
Skip to first unread message

Ricardo Amaral

unread,
Apr 23, 2020, 5:05:13 PM4/23/20
to Ansible Project
What exactly is the purpose of pre_tasks/post_tasks when one can just put "pre" tasks before the main tasks and "post" tasks after the main tasks in the "tasks" directive?

I've read the documentation many times and I can't understand the need for them. I must be missing something here, right?

Matt Martz

unread,
Apr 23, 2020, 5:08:11 PM4/23/20
to ansible...@googlegroups.com
Primarily they were introduced to provide execution order when using `roles:`.  `post_tasks` is probably mostly useless.  The execution order is:

pre_tasks
roles
tasks
post_tasks

On Thu, Apr 23, 2020 at 4:05 PM Ricardo Amaral <mas...@ricardoamaral.net> wrote:
What exactly is the purpose of pre_tasks/post_tasks when one can just put "pre" tasks before the main tasks and "post" tasks after the main tasks in the "tasks" directive?

I've read the documentation many times and I can't understand the need for them. I must be missing something here, right?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c158e6d6-7591-48c0-ba0b-e18ea70e279d%40googlegroups.com.


--
Matt Martz
@sivel
sivel.net

Ricardo Amaral

unread,
Apr 23, 2020, 5:11:18 PM4/23/20
to ansible...@googlegroups.com
What exactly is the purpose of roles then? 😅

I mean, is there a difference between roles and use include_role / import_role inside tasks?

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/un_30CiO-Ac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAD8N0v_Vc41yA_GyBs29N2GsfFAN%3DcJ7SkJX04tNa4aR%2BxLMtw%40mail.gmail.com.

Matt Martz

unread,
Apr 23, 2020, 5:16:51 PM4/23/20
to ansible...@googlegroups.com
`roles:` existed long before `include_role` and `import_role`.  Many on the core team would say that `import_role` and `include_role` are the future.  I personally would like to see `pre_tasks`, `roles`, and `post_tasks` deprecated.  Time will tell...

Ricardo Amaral

unread,
Apr 23, 2020, 5:23:01 PM4/23/20
to ansible...@googlegroups.com
So, in other words, with include_role, import_role, and tasks, one can do pretty much anything that roles, pre_tasks and post_tasks can do as well, right?

Thank you so much for your help, that clarifies things for me :)

Stay safe!

Reply all
Reply to author
Forward
0 new messages