Hello,
I understand this very basic, but I'm still learning... (And my apologies
for the long message.)
I built the playbook below so I can check which server is still in need of
an OS update based on its current kernel version:
---
- hosts: "{{ my_host }}"
remote_user: xxxxxx
vars:
server:
srvname: "{{ ansible_hostname }}"
kernel: "{{ ansible_kernel }}"
tasks:
- block:
- name: create list
set_fact:
serverlist: "{{ serverlist | default({}) | combine(
{item.srvname: item.kernel} ) }}"
with_items:
- "{{ server }}"
- name: print list
debug:
msg: "{{ serverlist }}"
- name: send list to file
lineinfile:
create: yes
line: "{{ serverlist | string }}"
path: "/shared/kernel.list"
when: (ansible_distribution == "OracleLinux") and
(hostvars[inventory_hostname].ansible_kernel !=
"4.18.0-305.10.2.el8_4.x86_64")
It's working, but I'd like to improve the way it presents the list of
servers in need of update... So, could you help with some hints on how I
could:
Make the "print list" task work in a way that instead of printing this:
TASK [print list]
**************************************************************************
ok: [xxxxxxxx] => {
"msg": {
"xxxxxxxxx": "4.18.0-240.10.1.el8_3.x86_64"
}
}
ok: [yyyyyyyy] => {
"msg": {
"yyyyyyyy": "4.18.0-240.10.1.el8_3.x86_64"
}
===> It would print something like (or closer to) this:
"msg": {
"xxxxxxxxx": "4.18.0-240.10.1.el8_3.x86_64'
"yyyyyyyy": "4.18.0-240.10.1.el8_3.x86_64
}
And, on the "send list to file" task, how would I have the file content
changed from this:
{'xxxxxxxxx ': '4.18.0-240.10.1.el8_3.x86_64'}
{' yyyyyyyy ': '4.18.0-240.10.1.el8_3.x86_64'}
===> To something like this:
xxxxxxxxx: 4.18.0-240.10.1.el8_3.x86_64
{yyyyyyyy: 4.18.0-240.10.1.el8_3.x86_64
I mean, without single quotes and curly braces.
I understand I could build another task to parse that file an "clean" it,
but, is there a way to do that while writing to the file?
Thanks a lot,
Alex
--
*The contents of this message and any attachment(s) are confidential,
proprietary to the City of Edmonton, and are intended only for the
addressed recipient. If you have received this in error, please disregard
the contents, inform the sender of the misdirection, and remove it from
your system. The copying, dissemination, or distribution of this message,
if misdirected, is strictly prohibited.*
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/c2760758-d9b8-4c77-82ba-4f42f1f172c6n%40googlegroups.com.