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
12
votes
3 answers

How to store command output into array in Ansible?

Essentially, I want to be able to handle "wildcard filenames" in Linux using ansible. In essence, this means using the ls command with part of a filename followed by an "*" so that it will list ONLY certain files. However, I cannot store the…
Viscosity
  • 311
  • 1
  • 2
  • 14
11
votes
2 answers

How to get just the version of the software when using ansible_facts.packages["zabbix-agent"]

I'm having an issue with using the package_facts module in Ansible. Basically, I just want to get the version of zabbix-agent installed as I need to do some stuff depending on which version is installed. Now I got this in a playbook task: - name:…
Francis Lee Mondia
  • 113
  • 1
  • 1
  • 5
10
votes
2 answers

Ansible - include vars file from remote host

I would like to include variables from a file on the remote host, rather than the control machine Ansible is running on. For example I have a file /var/database_credentials.yml (on my webserver) What's the best way to add variables from that file to…
Mikhail Janowski
  • 4,209
  • 7
  • 28
  • 40
10
votes
6 answers

Best way to get the IP address of the Ansible control machine

I am using Ansible and ufw to setup a firewall on my servers. As part of the ufw rules I would like to allow SSH from the Ansible control machine, but not from anywhere else. My question is - what is the best way to get the IP address of the control…
Cory
  • 22,772
  • 19
  • 94
  • 91
9
votes
1 answer

What is the difference between `ansible_architecture` and `ansible_machine` on Ansible?

I'm trying to find the architecture of the machine by using Ansible facts. We can gather information about the machine by running ansible -m setup command, as described in the documentation: Discovering variables: facts and magic…
shuuji3
  • 1,233
  • 13
  • 20
9
votes
2 answers

Undefined variable when running Ansible play

I am running multiple ansible plays defined in YAML files. In the last play I get the following error: {"failed": true, "msg": "The conditional check 'ansible_os_family == \"RedHat\"' failed. The error was: error while evaluating conditional…
Souciance Eqdam Rashti
  • 3,143
  • 3
  • 15
  • 31
8
votes
2 answers

Disable Ansible gather facts from the command line

To speed up execution of Ansible playbooks, I occasionally want to disable gathering facts during the setup phase. This can be done in the playbook by adding: gather_facts: False but how can it be controlled in the command line? I execute my…
Juuso Ohtonen
  • 8,826
  • 9
  • 65
  • 98
7
votes
3 answers

Ansible : How to copy everything from "Files" folders of a specific role

i ve an ansible role which looks like this : my-role ├─── files │ my-file-one │ my-file-two │ my-file-... │ my-file-n └─── tasks main.yml in my main.yml , i ve this recursive copy task , and i want to copy all…
firasKoubaa
  • 6,439
  • 25
  • 79
  • 148
7
votes
1 answer

ansible shell task erroring out without proper message

Team, I am trying to verify if sdd exists in mount command output. so when there is any, i am fine but when there is none, my task is simply failing instead of just telling me that no mounts exists. any hint how to tackle this? I don't want my task…
AhmFM
  • 1,552
  • 3
  • 23
  • 53
7
votes
1 answer

'dict object' has no attribute 'stdout' in Ansible Playbook

My playbook: - name: JBoss KeyStore and Truststore passwords will be stored in the password vault #shell: less "{{ vault }}" shell: cat "{{ vault }}" register: vault_contents tags: - BW.6.1.1.10 with_items: …
anish anil
  • 2,299
  • 7
  • 21
  • 41
6
votes
2 answers

Using if condition to assign True or False to gather_facts in Ansible doesnt work

--- - hosts: "{{ run_on_node|default('mysql_cluster_sql[0]')}}" connection: "{% if migrated is defined and migrated == 'yes' %}local{% else %}ssh{% endif %}" # This works as we are assigning non boolean value gather_facts: "{% if migrated is…
Shubham Saroj
  • 290
  • 2
  • 12
6
votes
1 answer

How to get a list of variables used in Ansible playbook?

I would like to get a list of variables used in an ansible playbook. I looked into the setup and debug module, but I doubt I can do this. Is there any generic way ?
Peter
  • 113
  • 1
  • 6
6
votes
2 answers

Ansible not reporting distribution info on Ubuntu 20.04?

Example on Ubuntu 18.04 reporting distribution info in 'ansible_facts': $ ansible -i hosts ubuntu1804 -u root -m setup -a "filter=ansible_distribution*" ubuntu1804 | SUCCESS => { "ansible_facts": { "ansible_distribution": "Ubuntu", …
JonB
  • 836
  • 1
  • 11
  • 15
6
votes
3 answers

How to gather facts about disks using Ansible

I am trying to write an Ansible playbook which will identify newly added disks on a RHEL machine. The plan is to run the playbook and cache the disks at that point in time as a fact prior to creating the new disks. After creating the new disks,…
AC-5
  • 193
  • 1
  • 1
  • 10
6
votes
3 answers

VARIABLE IS NOT DEFINED when trying to register output in playbook

I'm trying to register a variable with the output to a query of a F5 pool and I'm getting this error: "": "VARIABLE IS NOT DEFINED!", What is that I'm doing wrong? Any help appreciated. Thanks! --- - name: GRAB F5 FACTS hosts: f5 …
Jota
  • 69
  • 1
  • 1
  • 4
1
2
3
51 52