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
3
votes
1 answer
Ansible host file how to provide # in ansible_ssh_pass
I am new to ansible. I am facing a problem in hosts file. error output is below.
My question is : How do I escape the # in the ansible_ssh_pass.
I tried with ansible_ssh_pass="airtel\#121" and ansible_ssh_pass=airtel\#121 without double quotes both…

vaibhav singhal
- 883
- 8
- 9
3
votes
1 answer
Ansible set_fact not working at all for my task
$ ansible --version
ansible 2.10.8
I believe this is a different issue from Ansible's set_fact not working at all.
I have the following variable defined in group_vars/all.yml
nexus_repo = "dev_builds"
nexus_url = "https://nexus.company.com/{{…

Chris F
- 14,337
- 30
- 94
- 192
3
votes
3 answers
Ansible playbook_dir | basename
I want to remember current playbook folder name and pass it to another imported playbook. I set fact as "playbook_dir | basename" that returns proper folder name: appfolder. I pass it as bpm_folder to the imported playbook it is visible as appfolder…

Artyum
- 169
- 2
- 13
3
votes
1 answer
How to pass additional environment variables to the imported ansible playbook
I have a main_play.yml Ansible playbook in which I am importing a reusable playbook a.yml.
main_play.yml
- import_playbook: "reusable_playbooks/a.yml"
a.yml
---
- name: my_playbook
hosts: "{{ HOSTS }}"
force_handlers: true
gather_facts:…

Sanjesh M
- 341
- 2
- 6
- 22
3
votes
2 answers
How to create a one-time user prompt input in ansible?
I have a the following oversimplified ansible playbook:
- name: Prepare worker nodes
hosts: "{{ hosts }}"
serial:
- 1
- 3
remote_user: root
any_errors_fatal: true
vars:
hosts: nodes
reboot: false
tasks:
- pause:
…

tftd
- 16,203
- 11
- 62
- 106
3
votes
1 answer
Ansible fact sort data (Cisco ACI)
I'm trying to get a routing table from a Cisco ACI. I'm getting duplicate routes. Is there a way to sort them out?
example:
"10.127.32.70/32",
"10.127.32.70/32",
"10.127.32.70/32",
"10.127.32.70/32",
…

Muller
- 57
- 5
3
votes
1 answer
Ansible - problem with ansible_facts for packages in jinja template
I try to get all installed packages with Ansible and write them in a "pretty" way to a file.
Calling the module works:
- name: Gather the rpm package facts
package_facts:
manager: auto
In a Jinja template I am using a loop, what works too:
{%…
3
votes
2 answers
Ansible how to select hosts based on certain attributes and use their ip addresses to create a list at runtime
I have a specific question about data manipulation in ansible.
In my inventory file, I have a group called postgresql as below:
[postgresql]
host1 ansible_host=1.1.1.1 postgresql_cluster_port=5432 postgresql_harole=master
host2 ansible_host=2.2.2.2…

yzftnt
- 83
- 1
- 6
3
votes
1 answer
Ansible : multy loop into json file
I have as a source a json file that contains a list of NetworkFlow keys, and from which i would like to extract information to create security rules, using a double loop in ansible.
Below an example from my json file :
{
"Name":"Some_name",
…

Western__TN
- 53
- 2
3
votes
1 answer
A playbook with two roles: running role B complains with role A's code which successfully ran
I am experiencing a strange behavior: when I run role B, it complains role A's code which I can successfully run! I have reproduced this to this minimal example:
$ cat playbooka.yml
- hosts:
- host_a
roles:
- role: rolea
tags:
…

puravidaso
- 1,013
- 1
- 5
- 22
3
votes
1 answer
Iterating through two lists in Ansible
I'm writing an ansible playbook that creates users in an internal system through a call to an API where the request body contains all of the user information in json format.
Right now my playbook hold all of those variables in a list of dictionaries…

Sernut
- 33
- 4
3
votes
2 answers
Ansible get hostnames from one group as a variable to another play
Here is inventory file.
[abc]
host1
host2
[123]
host3
And main.yml
#play1
- hosts: abc
roles:
- { role: abc }
tasks:
...
#play2
- hosts: 123
roles:
- { role: 123 }
tasks:
debug: msg="{{inventory_hostname}}"
Basically I…

venkatama
- 55
- 1
- 7
3
votes
3 answers
How can I add new line "\n" character to Ansible variable
How can I add new line "\n" characters to Ansible variable mailbody
I set the below variable to ansible's mail module body attribute.
- set_fact:
mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' + PROFILE_NAME ~ '\n\nSERVER_NAME:'…

Ashar
- 2,942
- 10
- 58
- 122
3
votes
2 answers
How to get the current file name in ansible?
I am having an ansible script. It calls other scripts using include module.
I need to get the current file name in a variable.
For ex:
- include: Run-Config889.yml
Inside Run-Config889.yml, i need to get the file name Run-Config889.yml in a…

Samselvaprabu
- 16,830
- 32
- 144
- 230
3
votes
1 answer
Are there any vars that Ansible can merge?
Today I noticed that Ansible won't merge vars.
For example when I have something like
---
lvm_roles:
postgresql:
size: '10g'
path: '/var/lib/postgresql'
And in another place I have for example
---
lvm_roles:
sonarqube:
size:…

onknows
- 6,151
- 12
- 65
- 109