Create exception for service on a host

15 views
Skip to first unread message

Stefan Stefanovic

unread,
Apr 21, 2016, 11:01:43 AM4/21/16
to Ansible Project
Hi,

I guess this is fairly simple question, but I'm stuck with it...
I have a playbook that checks whether services are up on hosts and starts them if they are not in started state, for example:

- hosts: mailservers

  tasks:
        - name: Check amavis service, and start if needed.
          service: name=amavis state=started

What if i wanted to leave service in stopped state only on one of the hosts in "mailservers" group while performing this playbook? How can I achieve that?

Pogan

unread,
Apr 22, 2016, 10:42:02 AM4/22/16
to Ansible Project
I forgot to mention that idea is to do this through host variable file, and not through playbook itself.

Johannes Kastl

unread,
Apr 22, 2016, 2:44:13 PM4/22/16
to ansible...@googlegroups.com
On 22.04.16 16:42 Pogan wrote:
> I forgot to mention that idea is to do this through host variable file, and
> not through playbook itself.
>
Set a variable called bar for this host foo in the host_vars/foo file
and only execute the task, when this variable is not set:

- hosts: mailservers
tasks:
- name: Check amavis service, and start if needed.
service: name=amavis state=started
when: hostvars[foo]['bar']|default('') is undefined

I'm not sure what exactly has to be inside the default, but using
default avoids errors when the variable bar is undefined...

Johannes

signature.asc
Reply all
Reply to author
Forward
0 new messages