• Home
  • Recent Q&A
  • Java
  • Cloud
  • JavaScript
  • Python
  • SQL
  • PHP
  • HTML
  • C++
  • Data Science
  • DBMS
  • Devops
  • Hadoop
  • Machine Learning
in Ansible by
Q:
How would you access a variable of the first host in a group?

1 Answer

0 votes
by

Executes the following commands to access a variable of the first host in a group:

{{ hostvars[groups['webservers'][0]]['ansible_eth0']['ipv4']['address'] }}  

This command is accessing the hostname of the first machine in the webservers group. If you are doing this by a template, then use the jinja2 '#set', or you can use set_fact.

Related questions

0 votes
asked Nov 5, 2019 in Ansible by Robin
+3 votes
asked Feb 6, 2020 in Artificial Intelligence by GeorgeBell
...