Alright, thought it was going to be wasy, but I ended up scratching my head.
I have this tracker.txt
file, in a dictionary style formatting:
/oracle/db/19.0.0:
rollback:
30621255:
29213893:
29867728:
29802382:
28318139:
apply:
28318139:
29213893:
28788272:
31431771:
32044280:
I am trying to make the file contents look like this in the end:
/oracle/db/19.0.0:
rollback:
30621255: Success
29213893: Success
29867728: Success
29802382: Success
28318139: Success
apply:
28318139:
29213893:
28788272:
31431771:
32044280:
Here is my uf.yml
playbook:
---
- hosts: localhost
gather_facts: no
vars:
oracle_home: /oracle/db/19.0.0
rblist: [30621255, 29213893, 29867728, 29802382, 28318139]
tasks:
- name: update file
include: upd.yml
with_items:
- "{{ rblist | default([]) }}"
loop_control:
loop_var: plist_item
when: plist_item | default([])
and this is the upd.yml
included task file
---
- debug: msg={{ plist_item }}
- name: update the status
local_action replace: path=tracker.txt regexp="{{ plist_item }}:" replace="{{ plist_item }}: Success" after='rollback' before='apply'
But I get errors when I run this.
[oracle@anstrlsrv lib]$ ansible-playbook uf.yml
PLAY [localhost] ************************************************************************************************************************************************************************************************************************
TASK [update file] **********************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"reason": "We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: No JSON object could be decoded
Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/stage/ap/ansible/lib/upd.yml': line 4, column 94, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: update the status
local_action replace: path=tracker.txt regexp="{{ plist_item }}:" replace="{{ plist_item }}: Success" after='rollback' before='apply'
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
"}
fatal: [localhost]: FAILED! => {"reason": "We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: No JSON object could be decoded
Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/stage/ap/ansible/lib/upd.yml': line 4, column 94, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: update the status
local_action replace: path=tracker.txt regexp="{{ plist_item }}:" replace="{{ plist_item }}: Success" after='rollback' before='apply'
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
"}
fatal: [localhost]: FAILED! => {"reason": "We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: No JSON object could be decoded
Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/stage/ap/ansible/lib/upd.yml': line 4, column 94, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: update the status
local_action replace: path=tracker.txt regexp="{{ plist_item }}:" replace="{{ plist_item }}: Success" after='rollback' before='apply'
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
"}
fatal: [localhost]: FAILED! => {"reason": "We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: No JSON object could be decoded
Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/stage/ap/ansible/lib/upd.yml': line 4, column 94, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: update the status
local_action replace: path=tracker.txt regexp="{{ plist_item }}:" replace="{{ plist_item }}: Success" after='rollback' before='apply'
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
"}
fatal: [localhost]: FAILED! => {"reason": "We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: No JSON object could be decoded
Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/stage/ap/ansible/lib/upd.yml': line 4, column 94, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: update the status
local_action replace: path=tracker.txt regexp="{{ plist_item }}:" replace="{{ plist_item }}: Success" after='rollback' before='apply'
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
"}
PLAY RECAP ******************************************************************************************************************************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=5 skipped=0 rescued=0 ignored=0
Not sure where I am going wrong. Another option I thought was something that is documented here, but haven't ventured into it as I dont completely understand it yet: https://www.jeffgeerling.com/blog/2017/changing-deeply-nested-dict-variable-ansible-playbook
Appreciate any help.