With the cisco.iosxr.iosxr_config module a block replace expects the lines option:
TASK [Test stuff] ***********************************************************************************
fatal: [R1]: FAILED! => {"changed": false, "msg": "replace is block but all of the following are missing: lines"}
This is a slight issue when trying to issue J2 templates. When adding an empty lines to the the config block, I receive the following error (which makes sense):
Now, I'd prefer to have everything in separate J2 templates for maintainability, ease of use, the amount of if-else statements and the ability to use the template outside of ansible as well.
I can run the j2 template without the replace option, however if there are more lines on the router then I have in my template, I would like to have them removed, which currently isn't happening. I want to have that exact match.
In my opinion, the replace option should also accept the J2 template.
Remove the config if one or more lines is not matching with the running config. If the running config has more lines, this is not an exact match either. I expect the router to run the commands from before, which is to remove existing telemetry and then to paste the entire template.
ACTUAL RESULTS
~/c/ansible ansible-playbook -i hosts compare_config.yml --check --diff -vvv
ansible-playbook [core 2.14.2]
config file = /Users/alex/coding/ansible/ansible.cfg
configured module search path = ['/Users/alex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/alex/coding/ansible/.venv/lib/python3.9/site-packages/ansible
ansible collection location = /Users/alex/.ansible/collections:/usr/share/ansible/collections
executable location = /Users/alex/coding/ansible/.venv/bin/ansible-playbook
python version = 3.9.6 (default, Oct 18 2022, 12:41:40) [Clang 14.0.0 (clang-1400.0.29.202)] (/Users/alex/coding/ansible/.venv/bin/python3)
jinja version = 3.1.2
libyaml = True
Using /Users/alex/coding/ansible/ansible.cfg as config file
host_list declined parsing /Users/alex/coding/ansible/hosts as it did not pass its verify_file() method
script declined parsing /Users/alex/coding/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /Users/alex/coding/ansible/hosts as it did not pass its verify_file() method
Parsed /Users/alex/coding/ansible/hosts inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: compare_config.yml ************************************************************************
1 plays in compare_config.yml
PLAY [Changing telemetry settings] ******************************************************************
TASK [Test stuff] ***********************************************************************************
task path: /Users/alex/coding/ansible/compare_config.yml:29
redirecting (type: become) ansible.builtin.enable to ansible.netcommon.enable
fatal: [R1]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"admin": false,
"after": null,
"backup": false,
"backup_options": null,
"before": [
"no telemetry model-driven"
],
"comment": "configured by iosxr_config",
"config": null,
"disable_default_comment": false,
"exclusive": false,
"force": false,
"label": null,
"lines": null,
"match": "line",
"parents": null,
"replace": "block",
"src": "telemetry model-driven\n strict-timer\n destination-group COLLECTOR\n address-family ipv4 10.0.0.1 port 10000\n encoding json\n protocol grpc no-tls\n\n sensor-group SENSOR\n sensor-path openconfig-interfaces:interfaces\n \n sensor-path Cisco-IOS-XR-mpls-lsd-oper:mpls-lsd/label-range\n\n subscription SUBSCRIPTION\n sensor-group-id SENSOR sample-interval 60000\n destination-id COLLECTOR\n source-interface Loopback0\n"
}
},
"msg": "replace is block but all of the following are missing: lines"
}
PLAY RECAP ******************************************************************************************
R1 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
SUMMARY
With the cisco.iosxr.iosxr_config module a block replace expects the lines option:
This is a slight issue when trying to issue J2 templates. When adding an empty
lines
to the the config block, I receive the following error (which makes sense):Now, I'd prefer to have everything in separate J2 templates for maintainability, ease of use, the amount of if-else statements and the ability to use the template outside of ansible as well. I can run the j2 template without the replace option, however if there are more lines on the router then I have in my template, I would like to have them removed, which currently isn't happening. I want to have that exact match.
In my opinion, the replace option should also accept the J2 template.
ISSUE TYPE
COMPONENT NAME
cisco.iosxr.iosxr_config
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
MacOS Ventura 13.2.1 (latest)
STEPS TO REPRODUCE
J2 template example:
EXPECTED RESULTS
Remove the config if one or more lines is not matching with the running config. If the running config has more lines, this is not an exact match either. I expect the router to run the commands from
before
, which is to remove existing telemetry and then to paste the entire template.ACTUAL RESULTS