Page MenuHomeVyOS Platform

vyos_facts gather_subset does not update on second run in playbook
Closed, WontfixPublicBUG

Description

SUMMARY

on initial gather_subset: all variables are populated as expected.
However after a config change is made and gather_subset is ran again to update the variables the old values persist.

STEPS TO REPRODUCE
Run the below playbook against a vyos device.

---

- name: Network Getting Started First Playbook Extended
  connection: ansible.netcommon.network_cli
  gather_facts: false
  hosts: all
  tasks:

    - name: Get config for VyOS devices
      vyos.vyos.vyos_facts:
        gather_subset: all

    - name: Display the config
      ansible.builtin.debug:
        msg: "The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"

    - name: Update the hostname
      vyos.vyos.vyos_hostname:
        config:
          hostname: vyos-updated

    - name: Get changed config for VyOS devices
      vyos.vyos.vyos_facts:
        gather_subset: config

    - name: Display the changed config
      ansible.builtin.debug:
        msg: "The new hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"

EXPECTED RESULTS
Play name "Display the changed config" Should show the updated hostname from "Update the hostname"

ACTUAL RESULTS

PLAY [Network Getting Started First Playbook Extended] ********************************************************************************************************************

TASK [Get config for VyOS devices] ****************************************************************************************************************************************
ok: [10.25.3.51]

TASK [Display the config] *************************************************************************************************************************************************
ok: [10.25.3.51] => {
    "msg": "The hostname is vyos and the OS is VyOS 1.3.2"
}

TASK [Update the hostname] ************************************************************************************************************************************************
changed: [10.25.3.51]

TASK [Get changed config for VyOS devices] ********************************************************************************************************************************
ok: [10.25.3.51]

TASK [Display the changed config] *****************************************************************************************************************************************
ok: [10.25.3.51] => {
    "msg": "The new hostname is vyos and the OS is VyOS 1.3.2"
}

PLAY RECAP ****************************************************************************************************************************************************************
10.25.3.51                 : ok=5    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Details

Version
4.0.2
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Bug (incorrect behavior)

Event Timeline

syncer triaged this task as Normal priority.

After some investigation, it can be advised, that the described issue is to do with netcomm_cli module implementation used by VyOS Ansible Galaxy - namely, the ansible_net_version is set for a connection and stays so until reconnects and re-reads the modified hostname.
As such, this is currently outside of the collection's control.
That said, the issue can be easily avoided by reading ansible_facts mid-playbook:
Example Playbook:

---
- name: gather_subnet vyos_facts
  hosts: vyos_lab
  gather_facts: false
  tasks:
    - name: Get config for VyOS devices
      vyos.vyos.vyos_facts:
        gather_subset: all
        gather_network_resources: all

    - name: Display the config
      ansible.builtin.debug:
        msg: "The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"

    - name: Update the hostname
      vyos.vyos.vyos_hostname:
        config:
          hostname: test05

    - name: Get changed config for VyOS devices
      vyos.vyos.vyos_facts:
        gather_subset: config

    - name: Display the changed config
      ansible.builtin.debug:
        msg: "The new hostname is {{ ansible_facts['net_config'] |regex_search(\"set system host-name '([^']+)'\", '\\1') }} }} and the OS is {{ ansible_net_version }}"

Run and output:

$ ansible-playbook -i hosts -l vyos1.3 gather_subnet.yaml 

PLAY [gather_subnet vyos_facts] ***************************************************************************************************************************************************************************

TASK [Get config for VyOS devices] ************************************************************************************************************************************************************************
ok: [vyos1.3]

TASK [Display the config] *********************************************************************************************************************************************************************************
ok: [vyos1.3] => {
    "msg": "The hostname is test04 and the OS is VyOS 1.3.4"
}

TASK [Update the hostname] ********************************************************************************************************************************************************************************
ok: [vyos1.3]

TASK [Get changed config for VyOS devices] ****************************************************************************************************************************************************************
ok: [vyos1.3]

TASK [Display the changed config] *************************************************************************************************************************************************************************
ok: [vyos1.3] => {
    "msg": "The new hostname is ['test04'] }} and the OS is VyOS 1.3.4"
}

PLAY RECAP ************************************************************************************************************************************************************************************************
vyos1.3                    : ok=5    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

(.venv) [d368409@quasar ansible]$ ansible-playbook -i hosts -l vyos1.3 gather_subnet.yaml 

PLAY [gather_subnet vyos_facts] ***************************************************************************************************************************************************************************

TASK [Get config for VyOS devices] ************************************************************************************************************************************************************************
ok: [vyos1.3]

TASK [Display the config] *********************************************************************************************************************************************************************************
ok: [vyos1.3] => {
    "msg": "The hostname is test04 and the OS is VyOS 1.3.4"
}

TASK [Update the hostname] ********************************************************************************************************************************************************************************
changed: [vyos1.3]

TASK [Get changed config for VyOS devices] ****************************************************************************************************************************************************************
ok: [vyos1.3]

TASK [Display the changed config] *************************************************************************************************************************************************************************
ok: [vyos1.3] => {
    "msg": "The new hostname is ['test05'] }} and the OS is VyOS 1.3.4"
}

PLAY RECAP ************************************************************************************************************************************************************************************************
vyos1.3                    : ok=5    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0