I’m using the cat command with the command module to retrieve remote files content. With a loop within a find module I get filename and call a task, so like this:
[…]
name: Read the content of all files
command: /usr/bin/cat {{ _files_folder.path }}/{{ file_item }}.yaml
register: file_contents
become: true
become_user: root
[…]
I receive a list of string (with stdout_lines) or a normal output (with stdout) but I need to have a list because a the end I want to make a diff with another list of dict, like this:
ok: [10.10.10.1] => {
“daten_content”: [
{
“agents”: [
“aaa”,
“bbb”
],
“community”: {
“from xyzzy”
},
“disableDimensions”: true,
“Dimensions”: {
“HostGroup”: “abc”,
“Type”: “role”,
“env”: “TEST”
},
“fields”: [
[…]
Unfortunately I cannot retrieve what I need with a split or to pipe in list.
As anyone an idea how to do that or using another module?
I’m using the cat command with the command module to retrieve remote files content. With a loop within a find module I get filename and call a task, so like this:
[…]
name: Read the content of all files
command: /usr/bin/cat {{ _files_folder.path }}/{{ file_item }}.yaml
register: file_contents
become: true
become_user: root
[…]
I receive a list of string (with stdout_lines) or a normal output (with stdout) but I need to have a list
You say you receive a list, and you also say you want to have a list.
So, what is the problem then…?
Also, you didn’t say what you are actually trying to achieve. Do you need the file content? To do what?
In any case you could use the slurp module instead of command+cat:
The goal is to compare 2 files. The content of a file with a template file. First I’m trying to get the content of file then the template file and at the end I’ll do the comparaison.
So, here’s the result of my cat command:
[…]
“stdout_lines”: [
“# Ansible managed”,
“”,
“- agents:”,
" - "aaa\““,
" - \“bbb\““,
" community:",
" "#from": \“/etc/xyz\““,
" disableDimensions: true",
" Dimensions:",
" HostGroup: \“abc\““,
" Type: \“role\““,
" environment: \“TEST\““,
" fields:",
" - conversion: \“intg\““,
" name: "UCD-SNMP-MIB"",
" oid: \“.1.3…\““,
[…]
]
And here the template file:
[…]
“daten_content”: [
{
“agents”: [
“aaa”,
“bbb”
],
“community”: {
“\“#from": \“/etc/xyz\“
},
“disableDimensions”: true,
“Dimensions”: {
“HostGroup”: “abc”,
“Type”: “role”,
“env”: “TEST”
},
“fields”: [
{
“conv”: „int“,
“name”: “UCD-SNMP-MIB”,
“oid”: „.1.3…“
},
[…]
]
I need to have the same format file to compare them. I’ve try many way with output of cat command but I don’t find the right way and perhaps the’s an easiest way??
Comparing two files (one of them is already an ansible template?) is
not a goal, but rather an intermediate step.
What will you do with the result of this comparison?
If you can show your entire playbook, then it may get clear.
When something is added to the template then the file will be updated accordely but if you removed by example some parameters in template then nothing happens in the file. The goal is to compare the file and template to see if something has changed and finally modified it. The template must be always the standard.
Thanks for your help, H