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
235 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
825 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,850 points
498 views
+1 vote
1 answer

Is it possible to append a large amount of text to a file using Ansible?

Here is concept which you can follow. blockinfile is ...READ MORE

answered Jul 30, 2018 in Ansible by Atul
• 10,250 points
4,303 views
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,400 points
416 views
0 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
3,518 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
160 views