746
questions
-1
votes
0
answers
25
views
How can I pass / store data in an Ansible inventory plugin to / for consumption by a lookup or vars plugin? [closed]
I have written an inventory plugin to deal with the dynamics of hosts that aren't always reachable. Now I would like to implement a complementing lookup or vars plugin and that would be simplest to ...
0
votes
0
answers
46
views
using ansible facts or json_query, how do i get this mac address out of this json?
so i got json back from an openstack server query, but need to extract the mac address for the server. Getting the name and IP is easy enough but the mac address is hidden behind the vlan and a colon. ...
0
votes
1
answer
15
views
Ansible, Custom Fact - 'VARIABLE IS NOT DEFINED!: ''ogg_fact_general'' is undefined
Ansible custom facts, defined in /etc/ansible/facts.d. I can get their values manually just fine, like so:
[root@lnx000 templates]# ansible lnx072 -m ansible.builtin.setup | grep ogg_fact
...
0
votes
1
answer
47
views
Ansible Custom Facts for a Remote Node, not the Control Node - How is That Set Up?
A question about Ansible custom facts. I just started to learn those. Created and tested a couple on the Ansible Control Node lnx000.
For example, Ansible tells me the ogg_fact custom facts I put into ...
1
vote
2
answers
49
views
Ansible Gethering Cached OS facts Based on Conditions
I'm using the following to gather certain OS facts based on the ansible_system fact:
---
- name: Gather facts from all target hosts
hosts: all
gather_facts: false
tasks:
- name: Gather OS ...
-1
votes
2
answers
62
views
How to use only one variable out of 3 based on condition in ansible?
I have three variables to be register based on condition, it will run one task and register one variable, how can i use testing variable for respective task ?
---
- name: Test1
command: "echo ...
0
votes
2
answers
66
views
How to effectively access nested JSON objects in Ansible
I have a JSON structure mentioned below and i am not sure how to traverse lower down in the hierarchy:
"json": {
"count": 5,
"next": null,
"previous"...
1
vote
2
answers
176
views
Ansible how to convert boolean types true and false to corresponding strings
Here is my playbook, I didn't use the boolean type directly for compatibility with the previous version which was fetched from Inventory, I looked at the playbook and it was when: cluster_allinone == &...
0
votes
0
answers
20
views
Struggling to get specific information from ansible_facts output. What I can study to get a better understanding? jinja2, python, yaml?
I am trying to figure how to grab values reported by the ansible_facts. I don't know what I don't know, so I asking for help on what i need to learn in order to understand how to manipulate the data ...
0
votes
1
answer
54
views
Failed tasks list at the end of the playbook
Is it possible to somehow make it so that, after executing the playbook, at the end it prints all the tasks from the roles that failed, but the playbook was executed due to the ingore_errors option ...
-2
votes
1
answer
227
views
Ansible AAP: template error while templating string: No module named 'ansible.module_utils.compat.version'
This task is part of a role which decommissions VM's. To test one part of the role separately which is causing an issue, i have put it into a playbook.
The error i get is: "msg": "...
-1
votes
1
answer
47
views
Ansible: gather_subset - unable to get information on any fact with an underscore in the name
Trying to generate a report that shows the mount.device, mount.mount and mount.size_total information. Playbook runs without errors as long as I do not include anything that contains an underscore. ...
0
votes
1
answer
120
views
ansible run rescue only for instance where task failed
I am trying to run block of tasks and have rescue statement in case the task in block fails.
- block:
- name: Set shell session
shell: xyz
- fail:
msg: shell failed
rescue:
...
0
votes
1
answer
31
views
Ansible: how to filter json value based on another json value?
I have a query that returns:
ok: [oc-ar-ar-test-ansible-api] => {
"ivr_list.json": [
{
"announcement": {
"id": "0",
...
2
votes
1
answer
84
views
Ansible how to pass result of first task to block of tasks in other file
I have a task as below :
-name : Set-up
shell: abc
register: "{{item }}_result"
loop: {{ setu }}
-name: set of tasks
include_tasks: abc.yml
when "'{{ item }}_result'.rc!=0"
...
1
vote
1
answer
122
views
Ansible Array Variables
I have a problem using an array in ansible
My hosts_vars:
ivr:
- id: 1
name: "General"
announcement: "General-ES"
dests:
- option: "t"
id_dest:...
-2
votes
1
answer
91
views
classic solution to detect unreachable host in ansible does not work for a single host [duplicate]
My ansible inventory has 3 hosts one of which is unreachable i.e remhost2.
Below is desired working playbook along with the desired output.
[wladmin@remhost1 ~]$ cat inventory.hosts
[remhosts]
...
0
votes
2
answers
248
views
How to detect if host is WSL in Ansible playbook?
In Ansible, I need to run some roles only if the host is a WSL host.
How to detect that? I am looking for a form of:
- name: "Run only in WSL"
when: # what to put here?
# task definition
...
1
vote
1
answer
82
views
Using `lineinfile` to add a host variable in Ansible YAML inventory?
Hello everybody and thank you in advance for your help.
I have to add a variable stat: ON for some hosts in my YAML inventory that looks like:
all:
hosts:
host_1: {db: true, bckp: false}
...
1
vote
0
answers
556
views
Ansible variables and `gather_subset`
How do I find which ansible variable belong to which gather_subset group (https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html#parameter-gather_subset)?
Following an ...
2
votes
2
answers
190
views
Ansible task that ends all plays defined in playbook yaml file
To start with I am using:
ansible --version
ansible [core 2.16.3]
config file = None
configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']...
1
vote
1
answer
207
views
Changing `fact_path` in `ansible.cfg` does nothing
I am trying to change the default path of /etc/ansible/facts.d for storing Custom Facts to a different directory. As of now, if I store my Custom Facts in this path, I can retrieve them along with the ...
-2
votes
2
answers
55
views
I want to print a specific line/value in my stdout using ansible
In my playbook, I run the gitlab-rake backup command works as expected. Now I want to print the output for this example its "1706574679_2024_01_29_16.4.5_gitlab_backup.tar" but I'm ...
2
votes
1
answer
69
views
How does Ansible determine what version of a module to use (Windows/Unix)?
Ansible Core has a setup.py module for Unix systems (https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/setup.py). This is responsible for "fact gathering".
Ansible Windows ...
2
votes
3
answers
232
views
Search for an interface using its MAC address
I'm working on a playbook to set a static IP address for an interface, which is identified using MAC address.
My logic was to loop through the interfaces from Ansible facts and set IP when my MAC ...
1
vote
1
answer
84
views
Conditional task if a variable is set
I have a playbook with the interpreter (ansible_python_interpreter) set manually.
Then I have 2 tasks (foo, bar) as an example.
I only want bar executed if the interpreter is set to python2. How can I ...
2
votes
1
answer
40
views
Ansible: How To Compare 1 Host's Services with Multiple Host's Services?
I had an issue with comparing services for 2 server's with ansible. That is solved by the below yaml. My question is, how can I compare 1 host's service list with multiple host?
---
- hosts: test
...
-1
votes
2
answers
63
views
unable to use set_fact in ansible
unable to use set_fact in ansible. please help me out
"msg": [
"nilaj 15",
"ajin 15"
]
- set_fact:
name_list: "{{ name_list + item.split() | first }}&...
-1
votes
1
answer
87
views
Ansible - How to patch systems in an order and based on the operating system?
I have dynmaic inventory which has 10 nodes. 8 of them are RedHat and 2 of them are Ubuntu. The hosts are in random order.
I want to write a playbook so that it will patch the Ubuntu node at last ...
1
vote
1
answer
422
views
How do I `hostnamectl set-icon-name` via Ansible?
Red Hat has a command called hostnamectl set-icon-name. Is it correct to configure this using Ansible?
The usual command
ansible.builtin.shell: "hostnamectl set-icon-name {{ inventory_hostname }}&...
0
votes
1
answer
147
views
Ansible: How to compare 2 host's services with ansible?
I want to compare 2 Red Hat server's service list by Ansible and print out only the different service that is running.
For instance:
server 1 running services: a,b,c,d
server 2 running services: c,d,...
1
vote
2
answers
150
views
Convert win_service_info dictionary to lowercase
I am using the win_service_info module to store the services of a Windows machine into a dictionary. But, later, I want to search for a specific service by the path to the executable. I want this to ...
-2
votes
1
answer
110
views
Is there a list of tags accessible inside playbook?
I want to access an array of tags defined at execution. Is this possible?
For example:
ansible-playbook /dev/foo.yml --tags tag1
Can I read in some metadata containing value tag1 in foo.yml?
2
votes
1
answer
700
views
What's the proper way to enable fact storage in Ansible Automation Platform?
I need to enable fact (variable) storage so that a fact stored in one job template is available in a following job template in a workflow. Here's what my job templates look like:
Job template #1: Set ...
-1
votes
1
answer
126
views
How can I exclude task in playbook file for OS version?
We have the following example playbook file with import_playbook tasks:
- import_playbook: "{{playbook_folder}}/install_stage1.yml"
- import_playbook: "{{playbook_folder}}/...
0
votes
1
answer
806
views
Ansible: How to install RPM packages based on RHEL or OS version?
I use Ansible in order to install RPM packages on RHEL 7 and RHEL 8 Linux machines.
Is it possible to exclude the following packages only for RHEL 7 version? So yum install libselinux-python will be ...
1
vote
1
answer
1k
views
How to compare two registered values in Ansible?
I am a noobie in Ansible and struggling with comparing two registered values in my playbook.
I am fetching a list of codes from 2 different hosts and trying to compare them, but fail.
Expectation is ...
-3
votes
1
answer
201
views
Ansible - "stdout_lines": ["inactive"]} interpreted as fatal error
I am using Ansible to get a service status on my machines.
Unfortunately I get a fatal error that I am not so sure on how to fix. The code is working but this fatal error is really bothering me.
Code:
...
1
vote
2
answers
279
views
Ansible: How to use Jinja2 variable as dynamic YAML key?
I would like to create a dynamic YAML key name for the HTTP header of uri module within the task.
playbook.yml
- name: "Set variable"
set_fact:
ACCESS_TOKEN_TYPE: "TEST-TOKEN"...
0
votes
1
answer
722
views
Ansible: Task giving error when trying to parse 'ansible_facts'
I am fairly new to Ansible and am trying to create a playbook that will look at my Docker Swarm machines, check what NFS shares are already mounted, mount specified NFS shares from a list if they are ...
1
vote
2
answers
420
views
How can I access a top level variable containing a dot in Ansible?
I am trying to get a when condition to match a string value in a list of strings in Ansible. I'm defining my list variables in the all host inventory group. I call these list variables from many of ...
0
votes
1
answer
38
views
Ansible: How can I 'set_fact' o to define a variable after running a condition
I have a list {{ users }} of all users on a system, and I want to check if there is a specific file in their home directories, then define the new list of users when filename exist:
- name: Get all ...
-1
votes
2
answers
714
views
In Ansible, how to exit with sucess if any host is unreachable (without using ignore_unreachable)
I have the following playbook to get the first reachable host.
---
- hosts: all
gather_facts: yes
ignore_unreachable: yes
tasks:
- name: Get the first good host in the group
vars:
...
-1
votes
1
answer
148
views
How to pass variable from Ansible 'service_facts'?
Error when passing variable
ansible.builtin.set_fact:
apache_status: "{{ service_status['ansible_facts']['services']['{{ web_pkg }}.service']['state'] }}"
Below working fine
- name: ...
1
vote
1
answer
56
views
Ansible - how to compare items between 2 dictionaries
I have 2 dictionaries, 1 containing products and some variables for each product (including database location), and 1 containing databases in different locations and the way to connect to each.
...
1
vote
1
answer
2k
views
Ansible: How to hide password in 'shell'?
I am running a job in Jenkins which runs an Ansible playbook. The Ansible playbook fetches some credentials which I don't want it to be printed in the console log of Jenkins. The credentials are being ...
0
votes
1
answer
194
views
Transforming an ansible list of lists to a list of dicts
I finally learned how to do nested lists with product, but I don't like that I have to access the results by indices. product produces a list of lists, and I want a list of dicts.
For example, the ...
0
votes
1
answer
262
views
conditional test on ansible
I am trying to check if a specific package is installed or not using Ansible. Here is my task
- name: check whether a package called {{ pkg_name }} is installed or not
ansible.builtin.debug:
...
1
vote
0
answers
2k
views
Ansible hangup over SSH in Gathering Facts
I constantly encounter ansible's hangup over ssh connection. Only restarting the host helps.
But this is a very bad way out.
Hanging occurs at the TASK [Gathering Facts] stage. At the same time, if ...
1
vote
1
answer
555
views
Using json_query in Ansible to sort through complex JSON
I've run into a frustrating problem with Ansible and trying to parse a complex JSON object.
I need to find the physical volume, logical volume, disk name, and partition name for the devices that are ...