Okay, so the only way to exclude a host is at the play level, not the role 
level? 

It would be more ideal for my setup to exclude at the role level, that way 
I can ensure that any new play that is written that includes a particular 
role won't run it against blacklisted hosts. Moreover, having hosts 
excluded at the play level means that entire play will be skipped on 
blacklisted hosts, but perhaps only 1 of the roles in the play is 
blacklisted, and so if the blacklist/exclusion happened at the role level 
then the play would run on the blacklisted host and just complete all of 
the roles that were allowed.

For example, say I have a play called common.yml which sets up several 
common features on hosts. It is defined as follows:
  roles:
    - ntp
    - postfix
    - smartmontools

It would be nice to be able to just run the common.yml play against all 
hosts, and have it configure ntp and smartmontools on all hosts but only 
postfix on the hosts which aren't mailservers. Is this possible? If I add 
"- hosts: !mailserver" to common.yml, then the complete play will be 
skipped on "mailserver".

On Friday, 6 December 2013 13:48:03 UTC-6, Serge van Ginderachter wrote:
>
>
> On 6 December 2013 20:40, Andrew Martin <[email protected]<javascript:>
> > wrote:
>
>> Thanks for the information. In order to exclude a hostname called 
>> "mailserver", would I simply add a hosts line like this to the top of the 
>> postfix role's tasks/main.yml?
>>   - hosts:!mailserver
>>   - name: task1
>>   ...
>>   - name: task2
>>   ...
>> Will this override the list of hosts that I provide to the playbooks that 
>> include this role?
>>
>
> No. the hosts: keyword is to be set at play level, not at task level:
>
> - name: mailserver play
>>   hosts:
>>  postfixservers:
>> !mailserver
>>   tasks:
>>   - ...
>>   roles:
>>   - ...
>
>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to