Use this tag for questions regarding the Ansible inventory defined either as a static file (aka hosts file), or dynamically through external scripts (for example AWS EC2 inventory).
Questions tagged [ansible-inventory]
1172 questions
76
votes
6 answers
Where to store Ansible host file on Mac OS X
I am trying to get started with Ansible to provision my Vagrantbox, but I can’t figure out how to deal with host files.
According to the documentation the should be storred in /etc/ansible/hosts, but I can’t find this on my system (Mac OS X). I also…

StenW
- 1,964
- 5
- 24
- 27
74
votes
6 answers
Accessing inventory host variable in Ansible playbook
In Ansible 2.1, I have a role being called by a playbook that needs access to a host file variable. Any thoughts on how to access it?
I am trying to access the ansible_ssh_host in the test1 section of the following inventory host…

ali haider
- 19,175
- 17
- 80
- 149
54
votes
7 answers
Reload Ansible's dynamic inventory
I'm using Ansible to setup EC2 instances and deploy an app. There's a hosts script which gathers tags related servers and groups info. I'd like to run these actions as a single playbook, so
New instances are created if needed
Hosts script loads…

Vladimir Chervanev
- 1,574
- 1
- 12
- 14
53
votes
8 answers
Ansible provisioning ERROR! Using a SSH password instead of a key is not possible
I would like to provision with my three nodes from the last one by using Ansible.
My host machine is Windows 10.
My Vagrantfile looks like:
Vagrant.configure("2") do |config|
(1..3).each do |index|
config.vm.define "node#{index}" do |node|
…

Mark
- 5,994
- 5
- 42
- 55
43
votes
2 answers
How Exactly Does Ansible Parse Boolean Variables?
In Ansible, there are several places where variables can be defined: in the inventory, in a playbook, in variable files, etc. Can anyone explain the following observations that I have made?
When defining a Boolean variable in an inventory, it MUST…

dokaspar
- 8,186
- 14
- 70
- 98
40
votes
3 answers
Is it possible to write Ansible hosts/inventory files in YAML?
In the best practices page, there is an example that uses hosts.yml for hosts files:
In the docs, however, I can only find the INI syntax for writing hosts files.
What is the syntax for the inventory files in YAML?

Behrang
- 46,888
- 25
- 118
- 160
33
votes
2 answers
Run Ansible playbook without inventory
Consider if I want to check something quickly. Something that doesn't really need connecting to a host (to check how ansible itself works, like, including of handlers or something). Or localhost will do. I'd probably give up on this, but man page…

x-yuri
- 16,722
- 15
- 114
- 161
32
votes
5 answers
ansible returns with "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6))
I am running myserver in ubuntu:
+ sudo cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6…

Learner
- 1,686
- 4
- 19
- 38
32
votes
2 answers
List all ansible hosts from inventory file for a task
For a backup I need to iterate over all hosts in my inventory file to be sure that the backup destination exists. My structure looks like
/var/backups/
example.com/
sub.example.com/
So I need a (built-in) variable/method to…

falsch
- 1,425
- 2
- 14
- 21
30
votes
7 answers
Ansible - read inventory hosts and variables to group_vars/all file
I have a dummy doubt that keeps me stuck for a long time. I have a very banal inventory file with hosts and…

Tiago Sousa
- 301
- 1
- 3
- 5
26
votes
2 answers
Ansible: ansible_user in inventory vs remote_user in playbook
I am trying to run an Ansible playbook against a server using an account other than the one I am logged on the control machine. I tried to specify an ansible_user in the inventory file according to the documentation on…

techraf
- 64,883
- 27
- 193
- 198
24
votes
2 answers
how to specify user name in host file of ansible
I am using the host file as below,
[qa-workstations]
10.39.19.190 ansible_user=test ansible_ssh_pass=test
I am using below command to execute "whoami" command in host
root@Svr:~/ansible# ansible all -a "whoami" -i /etc/ansible/host
10.39.19.190 |…

Naggappan Ramukannan
- 2,564
- 9
- 36
- 59
19
votes
1 answer
How to make Ansible playbook run on first host in the group?
How can I run a playbook only on first host in the group?
I am expecting something like this:
---
- name: playbook that only run on first host in the group
hosts: "{{ groups[group_name] | first }}"
tasks:
- debug:
msg: "on {{…

Jakim
- 1,713
- 7
- 20
- 44
18
votes
2 answers
Ansible get hostname as defined in inventory
In my inventory I define hosts like this:
[server1]
141.151.176.223
I am looking for a variable which keeps the server1 name, as I am using it to define server hostname.
inventory_hostname is set to 141.151.176.223
ansible_hostname as well as…

Tom Raganowicz
- 2,169
- 5
- 27
- 41
18
votes
1 answer
Ansible: How to use variables defined in inventory file (hosts) in my playbook?
As the subject says. I have some host variables defined in my hosts inventory file. How do I access them in my playbook?
Here is an example. Based on all my research I was expecting foo and bar to be part of hostvars. I can put host specific…

Kashyap
- 15,354
- 13
- 64
- 103