Posted On: Feb 22, 2018
The trick lies in this command:
{{ hostvars[groups['webservers'][0]]['ansible_eth0']['ipv4']['address'] }}
Here, we’re pulling out the hostname of the first machine of the webservers group. If you’re doing this in a template, use the Jinja2 ‘#set’ or in a playbook, you can also use set_fact:
- set_fact: headnode={{ groups[['webservers'][0]] }} - debug: msg={{ hostvars[headnode].ansible_eth0.ipv4.address }}
Never Miss an Articles from us.
Ansible is an open source automation platform which can help you with configuration management, task automation and appl..
Ansible works on ‘agentless architecture’. It works by connecting to your nodes and pushes out Ansible modules to th..
Unlike other configuration management system, Ansible is the most sought after software applications these days. it off..