Run an Ansible task only when the hostname contains a string -


i have multiple tasks in role follows. not want create yml file handle task. have include web servers, couple of our perl servers require web packages installed.

- name: install perl modules   command: <command>   with_dict: perl_modules  - name: install php modules   command: <command>   with_dict: php_modules   when: <install php modules if hostname contains word "batch"> 

host inventory file

[webs] web01 web02 web03  [perl] perl01 perl02 perl03 perl-batch01 perl-batch02 

below should trick:

- name: install php modules   command: <command>   with_dict: php_modules   when: "'batch' in inventory_hostname" 

note you'll have couple of skipped hosts during playbook run.

inventory_hostname 1 of ansible's "magic" variables:

additionally, inventory_hostname name of hostname configured in ansible’s inventory host file. can useful when don’t want rely on discovered hostname ansible_hostname or other mysterious reasons. if have long fqdn, inventory_hostname_short contains part first period, without rest of domain.

source: ansible docs - magic variables , how access information other hosts


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -