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

vyos_config error when using template #294

Open
desultory opened this issue Feb 16, 2023 · 0 comments
Open

vyos_config error when using template #294

desultory opened this issue Feb 16, 2023 · 0 comments

Comments

@desultory
Copy link

desultory commented Feb 16, 2023

SUMMARY

When using vyos_config, there is an error when deploying config from a template:
[WARNING]: To ensure idempotency and correct diff the input configuration lines should be similar to how they appear if present in the running configuration on device including the indentation

ISSUE TYPE
  • Bug Report
COMPONENT NAME

vyos_config

ANSIBLE VERSION
ansible [core 2.13.7]
  config file = None
  configured module search path = ['/home/desu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/desu/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/lib/python-exec/python3.10/ansible
  python version = 3.10.9 (main, Dec 12 2022, 13:19:46) [GCC 11.3.0]
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
desu@boxxy ~/projects/hardened-refpolicy/policy/modules/system $ ansible-galaxy collection list vyos.vyos

# /usr/lib/python3.10/site-packages/ansible_collections
Collection Version
---------- -------
vyos.vyos  3.0.1

# /home/desu/.ansible/collections/ansible_collections
Collection Version
---------- -------
vyos.vyos  4.0.0

not sure how I can update this module, maybe it's using the 3.0.1 version?

CONFIGURATION
no changes
OS / ENVIRONMENT

Host: Linux boxxy 5.15.74.2-microsoft-custom-WSL2+ #20 SMP Tue Jan 10 11:55:17 CST 2023 x86_64 AMD Ryzen 9 7950X 16-Core Processor AuthenticAMD GNU/Linux
Remote host:

Linux vyos-primary 5.15.71-amd64-vyos #1 SMP Wed Sep 28 17:49:43 UTC 2022 x86_64 GNU/Linux
Version:          VyOS 1.4-rolling-202210020218
Release train:    sagitta

Built by:         [email protected]
Built on:         Sun 02 Oct 2022 02:18 UTC
Build UUID:       83b7cafe-a503-40c8-adce-691c201ffac3
Build commit ID:  5852d5de3ac606

Architecture:     x86_64
Boot via:         installed image
System type:      bare metal

Hardware vendor:  Dell Inc.
Hardware model:   PowerEdge R720xd
Hardware S/N:     x
Hardware UUID:    x

Copyright:        VyOS maintainers and contributors
STEPS TO REPRODUCE

The template is as follows:

{% for interface in interfaces %}
set interfaces {{interface.type}} {{interface.name}} description "{{interface.description}}"

{% if interface.type == 'wireguard' %}
set interfaces wireguard {{interface.name}} private-key {{interface.private_key}}
{% for peer in interface.peers %}
set interfaces wireguard {{interface.name}} peer {{peer.name}} allowed-ips {{peer.allowed_ips + "/32" if "/32" not in peer.allowed_ips}}
set interfaces wireguard {{interface.name}} peer {{peer.name}} public-key {{peer.public_key}}
{% endfor %}
{% endif %}

{% endfor %}

The relevant task/config:

# Configure the host interfaces based on the host variables and group variables
- name: Configure interfaces
  block:
    - name: Add inherited_intefaces to interfaces
      set_fact:
        interfaces: "{{interfaces + [item]}}"
      with_items: "{{shared_interfaces}}"
      when: inherited_interfaces is defined and item.name in inherited_interfaces

    - name: Configure interfaces
      vyos_config:
        src: configure_interfaces.j2
vyos_routers:
  hosts:
    vyos-primary:
      ansible_host: 192.168.200.2 # Using the not VRRP IP
      roles: vyos_router
      interfaces:
        - name: eth0
          type: ethernet
          enabled: true
          address: "1.2.3.4/32"
          description: "WAN interface"
          hw-id: "aa:bb:cc:dd:ee:ff"
      inherited_interfaces:
        - wg0
        - wg1
 Should contain variables which are common between hosts
shared_interfaces:
  - name: wg0
    type: wireguard
    address: "192.168.255.1/24"
    private_key: xx
    description: "VPN for office remote access {{inventory_hostname}}"
    peers:
      - name: b
        allowed_ips: "192.168.255.3"
        public_key: xx
      - name: a
        allowed_ips: "192.168.255.2"
        public_key: xx
  - name: wg1
    type: wireguard
    address: "192.168.254.1/24"
    private_key: xx
    description: "Admin VPN"
    peers:
      - name: b
        allowed_ips: "192.168.254.3"
        public_key: xx
      - name: a
        allowed_ips: "192.168.254.2"
        public_key: xx
EXPECTED RESULTS

I expect ansible to tell me which lines were changed, and not to apply config that is already present. If i run this playbook over and over, it says changes have been made but the resulting config stays the same. It seems to work if I use the normal lines function but I'd like to use the jinja templates for nested loops and such.

It seems this could be related to the escaped quotes?

ACTUAL RESULTS
ok: [vyos-secondary] => {
    "msg": {
        "changed": true,
        "commands": [
            "set interfaces ethernet eth5 description \"test ethernet\"",
            "set interfaces wireguard wg0 description \"VPN for office remote access vyos-secondary\"",
            "set interfaces wireguard wg1 description \"Admin VPN\""
        ],
        "failed": false,
        "filtered": [],
        "warnings": [
            "To ensure idempotency and correct diff the input configuration lines should be similar to how they appear if present in the running configuration on device including the indentation"
        ]
    }
}

[WARNING]: To ensure idempotency and correct diff the input configuration lines should be similar to how they appear if present in the running configuration on device including the indentation

@Qalthos Qalthos removed their assignment Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants