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 in Ansible by Jalil
107 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 by Akansha

Related Questions In Ansible

0 votes
1 answer
+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,810 points
255 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,240 points
2,447 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,380 points
145 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 in Ansible by Vaishu
1,116 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 in Ansible by Sam
77 views