Simple ansible playbook which reads the host name in the local machine and prints the result. echo $HOSTNAME shell command returns the host nname of the current machine. result is the output of Get hostnmae task and output is in the JSON format.
hostname module – Manage hostname. This module is part of ansible-core and included in all Ansible installations. In most cases, you can use the short module name hostname even without specifying the collections: keyword.
The necessary variable is inventory_hostname
.
- name: Install this only for local dev machine
pip: name=pyramid
when: inventory_hostname == "local"
It is somewhat hidden in the documentation at the bottom of this section.
You can limit the scope of a playbook by changing the hosts header in its plays without relying on your special host label ‘local’ in your inventory. Localhost does not need a special line in inventories.
- name: run on all except local
hosts: all:!local
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With