On Fri, Dec 28, 2012 at 7:47 PM, Dylan Silva <
dsi...@appdynamics.com> wrote:
> Thanks for the clarification. Unfortunately, something is going wrong with
> my playbook then, and I think I know the problem.
>
> So the command I am running is
>
> ansible-playbook /opt/ansible-playbooks/application/management/setup.yml
> --extra-vars="hosts=application1" --verbose
>
> My playbook has the following in it:
>
> ---
> - name: Manage the nginx nginx.conf for appserver1
> template: src=../installApplicationApp/templates/nginx-conf.j2
> dest=/etc/nginx/nginx.conf
> only_if: ${group_names} == 'appApp'
For one, it's "only_if: 'appApp' in $group_names" if you *did* want to
do that, because group_names is an array, and not a string.
But, really, this is not the way ansible likes to do things.
It really loves this (as Daniel said):
hosts: appApp
tasks:
- ...
hosts: appDb
tasks:
- ...
Groups are already a hosts slicing mechanism (it's what they were made
for), so it makes it much simpler that way. only_if only exists for
the weird corner cases, if you find it in your playbooks, you should
really ask if it needs to be there.
If you do have to slice hosts up by arbitrary discovered criteria
(like OS type), the group_by module is also excellent for this.
--Michael