Possible feature requrest: start execution at play number in a playbook

252 views
Skip to first unread message

Steven Truong

unread,
Jun 8, 2015, 5:04:21 PM6/8/15
to ansible...@googlegroups.com
Hi all,

Please excuse for my ignorance if there is a clean way to do the following:

hosts
[sm]
host1

[sw]
host2

myplaybook.yml
---
- hosts: all
  roles:
  - common

- hosts: sm
  roles:
  - role1
  - role2

- hosts: sw
  roles:
  - role1
  - role3

----------------------------

Assume that I can not combine tasks in role1 to common but I want to apply the run at the last play in the play book.  What are the options?  Since start-at-task will be the same for the role1 I can only start at 2nd play but not the the 3rd play.  I certainly can intro a fake role as the first role or a pre-tasks task (have not tried this yet) to the 3rd play to possibly achieve this but that is not the point of how we can achieve this in a more systematic and clean way in Ansible.


I can even break the plays into their own playbooks and then combine into a playbook:

mynewplaybook.yml
---
- include: play1.yml
  when: common is defined

- include: play2.yml 
  when: sm is defined

- include: play3.yml
  when: sw is defined


-----
And then use "-e sw=yes" to achieve this or even just create the mynewplaybook.yml or the original playbooks and then comment out the first 2 plays but then again would it be even possible to do start-at-play feature that is much cleaner than what I suggest here.

Please share your better approaches and comments on this.

Thank you very much and Ansible rocks.
Steven.


Brian Coca

unread,
Jun 8, 2015, 5:05:58 PM6/8/15
to ansible...@googlegroups.com
We already have something, not play, but task based --start-at-task,
also it uses the name not a number.



--
Brian Coca

Steven Truong

unread,
Jun 8, 2015, 5:11:15 PM6/8/15
to ansible...@googlegroups.com
The problem here is that role1 is the first role for play #2 and play #3 but I want to start with play #3 and I do not want to edit or comment my playbook.

Brian Coca

unread,
Jun 8, 2015, 5:14:20 PM6/8/15
to ansible...@googlegroups.com
--list-tasks should show the tasks and their names, --start-at-task
will then let you start at any task (does not matter if it was defined
in a role a play or an include).
> --
> 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 post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/55c5fd64-3658-479f-8105-c4e82b89a198%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Steven Truong

unread,
Jun 8, 2015, 5:43:25 PM6/8/15
to ansible...@googlegroups.com
Hi Brian,

Please excuse me if I am wrong but the problem with using the same ordering and role name in plays is that unless you can provide a scope such as play#.task_name then how do you apply a play preceded by another play with the same starting role.  And there are times I have to apply the same role to different hosts according to some orders of execution and then I need to go  back and fix things starting a play.

--list-tasks

play #2 (host1):
   setup abc
   .....

play #3 (host3):
   setup abc
  ....

If I used --start-at-task "setup abc" then how would I be able to achieve my goal as to start at play #3 and not play #2.  Certainly Ansible can still apply all tasks in play #2 and that could be ok in some cases but when I want  to save times or just to apply changes to hosts in starting at a specific play and avoid commenting out all previous plays up to the play I want to start with then would your suggestion work?


Thanks,
Steven.

Brian Coca

unread,
Jun 8, 2015, 6:34:45 PM6/8/15
to ansible...@googlegroups.com
no, in that case there is nothing that will work w/o editing the
playbook and introducing a 'checkpoint task' like debug: with a name
you can use as reference.
> https://groups.google.com/d/msgid/ansible-project/ef6fb481-bb4e-44f0-b6e0-5410673e3228%40googlegroups.com.

Brian Coca

unread,
Jun 8, 2015, 6:35:31 PM6/8/15
to ansible...@googlegroups.com
actually at that point i would recommend just writing 1 off plays that
do exactly what you want.
--
Brian Coca

Steven Truong

unread,
Jun 8, 2015, 6:49:42 PM6/8/15
to ansible...@googlegroups.com
Hi Brian,

This has become a pain point (at least for me) when I have to deal with setup a full kerberized CDH 5.4 + hive + sentry setup.  I certainly can break the playbook into playbooks but that might mean I would introduce even more playbooks in my environment and .... 

I just need to find a way to achieve this intelligently and without modifying my playbooks with comments and then I might forget to uncomment the plays or tasks.

Thanks for the conversation.
Steven.

Brian Coca

unread,
Jun 8, 2015, 6:51:52 PM6/8/15
to ansible...@googlegroups.com
i would propose smaller playbooks that do each group of tasks and a
larger 'container' playbooks that run full stacks using includes: of
the smaller ones.
> https://groups.google.com/d/msgid/ansible-project/dba8bf26-ed03-440f-8a12-7d054b6a5ced%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages