I'm a new Ansible user and enjoying it so far. I'm using Ansible to define and apply webserver configurations. I'm using playbooks. Say I have a role to install and configure Nginx, the tasks are defined at roles/nginx/tasks/main.yml
and referenced from ./site.yml
so they always runs when I provision new servers. Something like this example: https://github.com/ansible/ansible-examples/tree/master/wordpress-nginx/roles/nginx. That's working great but on occasion I want to explicitly stop, start or restart Nginx. I know how to achieve this using Ansible but my question is around conventions or common practices. Should I...
A. Create start, stop and restart tasks inside the Nginx role folder? And if so how should I declare and invoke them. Clearly I shouldn't just add them to main.yml or they'll be invoked whenever I provision a new server. Should I create roles/nginx/tasks/start.yml
, roles/nginx/tasks/stop.yml
etc and invoke them like ansible-playbook -i staging nginx/roles/stop.yml
.
B. Or should I not declare these in a playbook but rather execute them using ansible
, like ansible webservers -i staging -a "nginx stop" -s
.
C. Any other suggestions on the best way to accomplish this.
Thanks so much ( :