Best way to add reusable provisioning steps to existing roles

54 views
Skip to first unread message

itarchmerc

unread,
Jul 22, 2014, 4:32:33 PM7/22/14
to ansible...@googlegroups.com
What would be the best method to add reusable provisioning steps to existing roles?  I am looking to try and accomplish the following:

  • Ideally this could be it's own role, or in some way reusable so I could tie it to any role
  • It would pull in all the needed parameters from group or host vars
  • It would only be called if I sent something like ansible-playbook -e "provision=yes", otherwise the role would run as written without provisioning an instance
  • I would like a way to easily extend this for additional providers (e.g. EC2, VMWare, GCE, etc)
I have been able to add provisioning steps into an existing role by using a separate task, but I feel like there is a better and more reusable way to approach this.  Please let me know if additional clarification is needed.  Thanks.

Michael Peters

unread,
Jul 22, 2014, 5:36:55 PM7/22/14
to ansible...@googlegroups.com
I actually tackle this another way. I write provisioning playbooks
(not a role) that will create the server on the provider. And then
when it's finished, run some bootstrapping steps. After that is done,
use add_host to add it to the right group and then include the
role-level playbook.

This way the roles don't need to know anything about provisioning. The
step to provision new servers is a different command and as soon as a
server is provisioned it's handed off to the appropriate roles to get
it configured. And because our inventory is dynamic the new server
will be included in subsequent runs too.
> --
> 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/0c4abae5-44b8-45fc-b825-95d45933d24d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Michael DeHaan

unread,
Jul 23, 2014, 9:26:47 AM7/23/14
to ansible...@googlegroups.com
Yep, use roles to describe the states and behaviors, and include those roles in multiple playbooks as appropriate.

If you have a configure.yml as a playbook, the "provision.yml" could just include it as the very last line of the playbook, making it easy to run things together using the "add_hosts" trick as described in (for example) the EC2 guide.






itarchmerc

unread,
Jul 23, 2014, 11:38:24 AM7/23/14
to ansible...@googlegroups.com
Thank you for the suggestions.  I have implemented and tested them and it's all working great.
Reply all
Reply to author
Forward
0 new messages