I'm trying to store what the playbook of ansible outputs to a local file. I think I already accomplished my goal but it should store more than one line. The playbook outputs two lines, but on the local file, only stores one
This is my playbook:
---
- hosts: all
become: true
tasks:
- name: Comando para el hostname
shell: hostname
register: hostname_output
- name: Mostrar el hostname
debug:
msg: "{{ hostname_output.stdout }}"
- name: Comando para el timer
shell: cat /etc/systemd/system/runrestic.timer | grep OnCalendar*
register: timer_output
- name: Mostrar el timer
debug:
msg: "{{ timer_output.stdout }}"
- name: guardar en fichero local
lineinfile:
dest: /home/rvargas/register.txt
line: "{{ hostname_output.stdout, timer_output.stdout }}"
delegate_to: localhost
This is the ouput I get running the playbook:
rvargas@DESKTOP-4NPLJA6:/etc/ansible$ ansible-playbook --ask-become-pass oncalendar.yml
BECOME password:
PLAY [all] **************************************************************************
TASK [Gathering Facts] **************************************************************
ok: [192.168.1.68]
ok: [192.168.1.109]
TASK [Comando para el hostname] *****************************************************
changed: [192.168.1.109]
changed: [192.168.1.68]
TASK [Mostrar el hostname] **********************************************************
ok: [192.168.1.109] => {
"msg": "grafana-prom"
}
ok: [192.168.1.68] => {
"msg": "ansible"
}
TASK [Comando para el timer] ********************************************************
changed: [192.168.1.109]
changed: [192.168.1.68]
TASK [Mostrar el timer] *************************************************************
ok: [192.168.1.109] => {
"msg": "OnCalendar=daily"
}
ok: [192.168.1.68] => {
"msg": "OnCalendar=*-*-* 2:00:00"
}
TASK [guardar en fichero local] *****************************************************
changed: [192.168.1.109 -> localhost]
changed: [192.168.1.68 -> localhost]
PLAY RECAP **************************************************************************
192.168.1.109 : ok=6 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.1.68 : ok=6 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
And this is what is stored in my file
rvargas@DESKTOP-4NPLJA6:/etc/ansible$ cat /home/rvargas/register.txt
('ansible', 'OnCalendar=*-*-* 2:00:00')
This is what I actually expect:
rvargas@DESKTOP-4NPLJA6:/etc/ansible$ cat /home/rvargas/register.txt
('ansible', 'OnCalendar=*-*-* 2:00:00')
('grafana-prom', 'OnCalendar=daily')