Use this tag for questions regarding Ansible facts - values discovered by the setup module of Ansible or pulled from ohai/facter.
Questions tagged [ansible-facts]
768 questions
4
votes
3 answers
Ansible set_fact local and use on remote hosts
I'm trying to get a version on local and use it as a var in other remote hosts
Using the set_fact module in ansible
On local
- name: Set code version
shell: wget -O - -o /dev/null wget -O - -o /dev/null…

user3292394
- 609
- 2
- 11
- 24
4
votes
2 answers
How to select mandatory character when generating random password with ansible?
I create a random password with Ansible. 4 characters in length.
- hosts: localhost
vars:
pwd_alias: "{{ lookup('password', '/dev/null length=4 chars=ascii_letters,digits,hexdigits,punctuation' ) }}"
user: root
tasks:
- debug:
…

Birol Emekli
- 155
- 3
- 11
4
votes
1 answer
Listing more than 100 records in Route 53 using Ansible
I'm currently using the route53_facts module on a project. I have 250 record sets in one hosted zone. I'm having difficulty with listing all record sets in that zone. The Route 53 API works by returning pages of maximum 100 records at a time. In…

Aaron Hastings
- 327
- 2
- 10
4
votes
4 answers
Unable to access hostvars when the inventory_host is inserted as a variable
I have a jinja2 template, and I'm trying to loop through a host group, and insert the ipv4 address of all the hosts in my template. But I'm getting an error when I do it, even though the way I'm doing it is the way every post and article suggest it…

Harald
- 65
- 1
- 1
- 8
4
votes
1 answer
How to sort with JMESPath in ansible playbook?
I have an array returned by curl from consul during playing ansible playbook:
[
{
"Node": {
"Node": "test-eu-west-2-staging-0"
},
"Node": {
"Node": "test-nyc1-staging-0"
},
…

Konstantin Shestakov
- 457
- 4
- 7
- 13
4
votes
1 answer
Why Ansible facts not available in Roles section?
Question
Why Ansible facts such as ansible_distribution are not available in Roles section?
---
- name: Test
hosts: all
tasks:
- name: debug
debug:
msg: "{{ ansible_distribution }}" <----- Works
roles:
- "{{…

mon
- 18,789
- 22
- 112
- 205
4
votes
1 answer
Ansible: ansible_domain or facter_domain - How to get domain value of a hostname mentioned in inventory file
Ansible 1.9.2 / 1.9.4
CentOS 6.7
In my invetory file, I have:
[zabbix_server]
zabbix.dev-white.projectname.jenkins
[some_other_zabbix_server]
someotherzabbix.dev-blue.project.jenkins ansible_ssh_host=10.120.133.11
When I run:
ansible -m setup -i…

AKS
- 16,482
- 43
- 166
- 258
4
votes
3 answers
Use Ansible control master's IP address in Jinja template
I would like to insert an IP address in to a J2 template which is used by an Ansible playbook. That IP adress is not the address of the host which is being provisioned, but the IP of the host from which the provisioning is done. Everything I have…

BlueM
- 3,658
- 21
- 34
4
votes
2 answers
Discover management IP and use it in a template
I'm trying to setup my sshd_config file using Ansible. For design reasons (we have both virtual and physical machines, with different NICs) the management interface is not fixed, so in my template I cannot just put
{{ ansible_eth0.ipv4.address…

Ignacio Verona
- 655
- 2
- 8
- 22
3
votes
3 answers
Ansible facts which are guaranteed to be collected for all hosts
If I run a playbook from start to finish, it gathers facts and then runs roles. But usually I don't do that: I just run roles directly (via their tags). So the facts are not gathered, and I get errors. To fix this I must remember to run a special…

lonix
- 14,255
- 23
- 85
- 176
3
votes
1 answer
Ansible: How to execute set_fact module from within ansible action plugin python code
I am writing a custom Action Plugin for Ansible which I use in my playbook and I am trying to set a variable that will be used in the next task, in the playbook, by a (custom) module.
Effectively, the playbook equivalent of what I am trying to mimic…

hs14428
- 109
- 5
3
votes
2 answers
Variable is undefined when running Ansible 'debug' ad-hoc
Could you explain why following behaviour happens. When I try to print remote Ansible IP with following playbook everything works as expected:
---
- hosts: centos1
tasks:
- name: Print ip address
debug:
msg: "ip:…

verb
- 69
- 5
3
votes
2 answers
ansible_facts.packages "skipping" my package check
I would like to check if my package is installed, but I would like to have all package types with a name.
Let me explain: I am looking for the OB2 package, but there are plenty of them, so I am looking for OB2* but it skips my search.
I tested with…

anthony tarenta
- 31
- 1
- 6
3
votes
2 answers
How to unset a Variable in Ansible?
Is there a possibility to unset a fact (variable) in Ansible?
Unset in such a way that the check is defined fails.
For execution decisions I regularly check conditions with is defined. However, it may be necessary to unset these before execution,…

phanaz
- 1,188
- 8
- 17
3
votes
2 answers
Creating a list of system interface names along with their mac addresses
I'm trying to create a list of interface names along with their mac addresses from a Debian 11 server, initially, I was trying to get the mac addresses in order only but now I realize I need a list that looks like this:
eth0
eth1…

Sinux
- 94
- 7