'Ansible, error in getting results for multiple register command
I tried to get results as follow:
- name: Populate known_hosts
hosts: spectrum_scale
gather_facts: no
tags: set_known_hosts
become: true
tasks:
- name: Get hosts list from known_host
ansible.builtin.shell:
cmd: "cat /root/.ssh/known_hosts |
grep {{ hostvars[item].ansible_fqdn }}"
with_items: "{{groups['spectrum_scale']}}"
ignore_errors: yes
register: hosts2add
- name: Scan for SSH client keys
ansible.builtin.shell:
cmd: "ssh-keyscan {{ hostvars[h2a_r.item].ansible_fqdn }},
{{ hostvars[h2a_r.item].ansible_default_ipv4.address }}
2>/dev/null"
loop: "{{ hosts2add.results }}"
loop_control:
loop_var: h2a_r
when: h2a_r.rc
register: ssh_scan
- name: Display debug
ansible.builtin.debug:
msg: "FINGERPRINT TO ADD {{ ss_r.stdout_lines }}"
# var: ss_r.stdout_lines
loop: "{{ ssh_scan.results }}"
loop_control:
loop_var: ss_r
I got the error:
{"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout_lines'
What's really weird is that if use the var instead of msg I got the value I need
var: ss_r.stdout_lines
I found an old post (Ansible register result of multiple commands) but that solutions suggested seem not work for me
Thank you for helping
Solution 1:[1]
I'm not sure what you're looking for, but result is a dictionary who contains all the values you stored.
if you're going to use loop for loops you need to pass dict2items
E.G.:
- name: Display debug
ansible.builtin.debug:
msg: "FINGERPRINT TO ADD {{ ss_r.stdout_lines }}"
# var: ss_r.stdout_lines
loop: "{{ ssh_scan.results | dict2items }}"
loop_control:
loop_var: ss_r
Probably that resolve the error message you stated before.
Solution 2:[2]
You might convert all styling to element attributes using SVGOMG:
replace your embedded
<image>element by the decoded data url content. Your parent svg should look something like this:<!-- parent svg --> <svg xmlns="http://www.w3.org/2000/svg" > <!-- embedded svg decoded data url --> <svg xmlns="http://www.w3.org/2000/svg" height="50000" width="50000"> <style> .gliffy-rte-text { } </style> </svg> </svg>Use SVGOMG "inline styles" and "style to attribute"parameter:
You should disable all other optimizing parameter, since they might strip to many other attributes.
Expected before result
<svg viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
<style>
circle{
fill:none;
stroke: orange;
stroke-width:10;
}
</style>
<circle cx="128" cy="128" r="100"/>
</svg>
After
<svg viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
<circle cx="128" cy="128" r="100" fill="none" stroke="orange" stroke-width="10"/>
</svg>
Solution 3:[3]
Open the wrapper file in a browser. Right-click on the area containing the embedded SVG, and choose "Save (image) as...". If the wrapper contains multiple <image> tags, you will have to save them to separate files, but at least they will be in a form Inkscape can handle.
If you want to get them all together in one SVG file again, you will have to re-import them via the Inkscape import function. Take care to select 'Include as editable object', or you will end up right where you started:
The speculations above about CSS are unsubstantiated, btw. Inkscape will convert the content of a <style> element into inline style attributes, but otherwise handle them correctly. What happened is stated quite clearly in the above screenshot: data URLs embeded via an <image> tag will not be editable in Inkscape.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | malpanez |
| Solution 2 | herrstrietzel |
| Solution 3 | ccprog |


