Questions tagged [ansible-facts]

Use this tag for questions regarding Ansible facts - values discovered by the setup module of Ansible or pulled from ohai/facter.

768 questions
185
votes
10 answers

Where can I get a list of Ansible pre-defined variables?

I see that Ansible provide some pre-defined variables that we can use in playbooks and template files. For example, the host IP address is ansible_eth0.ipv4.address. Googleing and searching the docs I couldn't find a list of all available…
neves
  • 33,186
  • 27
  • 159
  • 192
161
votes
12 answers

Ansible: get current target host's IP address

How do you get the current host's IP address in a role? I know you can get the list of groups the host is a member of and the hostname of the host but I am unable to find a solution to getting the IP address. You can get the hostname by using…
SJC
  • 2,767
  • 4
  • 20
  • 31
101
votes
10 answers

How to get an arbitrary remote user's home directory in Ansible?

I can do that with shell using combination of getent and awk like this: getent passwd $user | awk -F: '{ print $6 }' For the reference, in Puppet I can use a custom fact, like this: require 'etc' Etc.passwd { |user| …
Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68
59
votes
3 answers

How to get the first element of a list from the output of setup module in Ansible?

I received the following data from the setup module: "ansible_nodename": "3d734bc2a391", "ansible_os_family": "RedHat", "ansible_pkg_mgr": "yum", "ansible_processor": [ "AuthenticAMD", "AMD PRO A10-8700B R6, 10 Compute Cores…
thinkingmonster
  • 5,063
  • 8
  • 35
  • 57
55
votes
3 answers

Ansible - actions BEFORE gathering facts

Does anyone know how to do something (like wait for port / boot of the managed node) BEFORE gathering facts? I know I can turn gathering facts off gather_facts: no and THEN wait for port but what if I need the facts while also still need to wait…
silverdr
  • 1,978
  • 2
  • 22
  • 27
42
votes
4 answers

Check if arrays are defined and not empty in ansible

I have the following code - set_fact: MY_HOSTNAME: "SOME VALUE" MY_SERVER: "00.00.00.00" - name: Get MY server set_fact: MY_SERVER: "{{ groups[MY_HOSTNAME][0] }}" when: groups[MY_HOSTNAME] is defined In the above code,…
kosta
  • 4,302
  • 10
  • 50
  • 104
34
votes
4 answers

Force fact-gathering on all hosts

I'm sitting in front of a fairly complex Ansible project that we're using to set up our local development environments (multiple VMs) and there's one role that uses the facts gathered by Ansible to set up the /etc/hosts file on every VM.…
tehK
  • 2,265
  • 4
  • 17
  • 16
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
22
votes
4 answers

How to filter gathering facts inside a playbook?

I'm working on a role that only needs to gather a single fact. Performance it's a concern and I know that gathering facts it's time-consuming. I'm looking for some way to filter gather_facts inside a playbook, this will allow me to gather only the…
Bernardo Vale
  • 3,224
  • 4
  • 21
  • 34
17
votes
4 answers

Fastest way to gather facts to fact cache

I am trying to make Ansible work with --limit and to do that I need facts about other hosts, which I am caching with fact_caching. What command should I run so that it simply gathers all the facts on all the hosts and caches them, without running…
Sepehr Nazari
  • 3,744
  • 4
  • 12
  • 17
16
votes
3 answers

Ansible: How to specify an array or list element fact with yaml?

When we check hostvars with: - name: Display all variables/facts known for a host debug: var=hostvars[inventory_hostname] We get: ok: [default] => { "hostvars[inventory_hostname]": { "admin_email": "admin@surfer190.com", …
tread
  • 10,133
  • 17
  • 95
  • 170
15
votes
2 answers

How to use a dictionary of registered ansible variables in vars?

I want to pass multiple variables to a task using vars. Currently, I am doing it like below vars: var1_name: "var1_value" var2_name: "var2_value" As the number of variables can grow in size, I'd rather prefer to pass the dictionary of…
user3086551
  • 405
  • 1
  • 4
  • 13
15
votes
3 answers

How do you change ansible_default_ipv4?

I'd like to change ansible_default_ipv4 to point to eth1 instead of eth0. Can I do this in either the playbook or via the --extra-vars option?
jd50
  • 235
  • 2
  • 3
  • 6
12
votes
2 answers

copy files to server from relative path in ansible

How can I pass a relative path so that Ansible can copy files from node/keys and copy them to a server? The playbook is ansible/playbook. My directory structure is: ├── ansible │   ├── inventory │   └── playbook ├── node │   ├── keys │   ├──…
TechChain
  • 8,404
  • 29
  • 103
  • 228
12
votes
1 answer

Ansible: specify inventory file inside playbook

So from what I gather, we can use ansible.cfg to set the default inventory file that ansible looks for when running a playbook. We can also override that inventory by using the -i parameter when running an ansible playbook via the command line. Is…
user2221830
  • 163
  • 2
  • 11
1
2 3
51 52