Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace: block is not possible with a separate J2 template #343

Closed
naveci opened this issue Feb 23, 2023 · 1 comment
Closed

Replace: block is not possible with a separate J2 template #343

naveci opened this issue Feb 23, 2023 · 1 comment
Assignees

Comments

@naveci
Copy link

naveci commented Feb 23, 2023

SUMMARY

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):

TASK [Test stuff] ***********************************************************************************
fatal: [R1]: FAILED! => {"changed": false, "msg": "parameters are mutually exclusive: lines|src"}

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
  • Bug Report
COMPONENT NAME

cisco.iosxr.iosxr_config

ANSIBLE VERSION
ansible [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
  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
COLLECTION VERSION
# /Users/alex/coding/ansible/.venv/lib/python3.9/site-packages/ansible_collections
Collection  Version
----------- -------
cisco.iosxr 4.1.0

# /Users/alex/.ansible/collections/ansible_collections
Collection  Version
----------- -------
cisco.iosxr 4.1.0
CONFIGURATION
CONFIG_FILE() = /Users/alex/coding/ansible/ansible.cfg
HOST_KEY_CHECKING(/Users/alex/coding/ansible/ansible.cfg) = False
OS / ENVIRONMENT

MacOS Ventura 13.2.1 (latest)

STEPS TO REPRODUCE
---
- name: "Changing telemetry settings"
  hosts: all
  gather_facts: false

  tasks:
    - name: Test stuff
      cisco.iosxr.iosxr_config:
        src: templates/test.j2
        before: "no telemetry model-driven"
        replace: block

J2 template example:

telemetry model-driven
 destination-group COLLECTOR
  address-family ipv4 10.0.0.1 port 10000
   encoding json
   protocol grpc no-tls
  !
 !
 sensor-group SENSOR
  sensor-path openconfig-interfaces:interfaces
  sensor-path Cisco-IOS-XR-mpls-lsd-oper:mpls-lsd/label-range
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
 ~/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
@ashwini-mhatre
Copy link
Collaborator

closing this as #435 fixed this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants