Access Inventory file - Ansible

0 votes

I have my inventory file 

[my_hosts]
my_host ansible_ssh_host=123.123.125.126
my_host2 ansible_ssh_host=234.234.234.237

How do I access the alias variable in a playbook/template?

Jan 24, 2019 in Ansible by Jalil
792 views

1 answer to this question.

0 votes

You can just use {{ ansible_ssh_host }}

Inventory:

[my_hosts]
my_host ansible_ssh_host=127.0.0.1 my_host_alias=my_host

Playbook:

---
- name: Example
  user: ubuntu
  hosts: all

  tasks:
    - name: whatever
      debug: msg="Myhost is {{ ansible_ssh_host }}"

    - name: whatever
      debug: msg="My host alias is {{ my_host_alias }}"
answered Jan 24, 2019 by Akansha

Related Questions In Ansible

0 votes
1 answer

What is the difference between the host file and an inventory file in ansible?

Actually both are same. hosts file is ...READ MORE

answered Feb 12, 2019 in Ansible by Amith
• 140 points
7,186 views
0 votes
1 answer

How to set dynamic host inventory file for docker in Ansible?

Hi@akhtar, In a configuration especially a container setup such ...READ MORE

answered Sep 20, 2020 in Ansible by MD
• 95,440 points
1,718 views
+1 vote
1 answer

Ansible: Deleting matching IPs from hosts file using regex

Ansible notation isn't the same as YAML ...READ MORE

answered Jul 25, 2018 in Ansible by DareDev
• 6,890 points
1,987 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,460 views
+2 votes
1 answer
0 votes
1 answer

Ansible playbook to wget a file

Hey @Celia, one recommendation, try not using ...READ MORE

answered Jan 16, 2019 in Ansible by Vaishu
16,546 views
0 votes
1 answer

Configuring SSH Access to the Ansible Hosts

Hey @Shakira, follow these steps: Execute the following ...READ MORE

answered Jan 17, 2019 in Ansible by Sam
998 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP