Ansible Vyos BGP configuration

I have this ansible task configured.

   - name: 'BGP address family configuration'
      vyos.vyos.vyos_bgp_address_family:
            config:
              as_number: '65535'
              address_family:
                - afi: 'ipv4'
                  networks:
                    - prefix: '172.30.0.0/24'
                - afi: 'ipv6'
                  networks:
                    - prefix: '2001:ef8:1::/48'

The task shows ok but does not execute the configuration.

TASK [BGP address family configuration] *********************************************************************************************************************************************************************
ok: [bgp_vyos]

I am not sure what is the error here?

As an option, you can use vyos_config

Yes @Viacheslav I saw that but don’t want to use vyos_config. I would prefer using BGP modules.

Hi @qwerty , can you run this playbook again with -vvv option and check the output?

Bgp was fully rewriting in 1.4. For example you don’t need set ASN for each bgp config anymore as it declared only one time.
So if this module works for some 1.1.x version most likely it won’t work in 1.4

Hi @Viacheslav I am using Vyos 1.3.x version not 1.4
I applied -vvv option and I am getting below output.

[root@IMG ansible]# ansible-playbook -vvv -i inventory.ini main_bgp.yml
ansible-playbook 2.9.25
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/usr/share/ansible/plugins/modules’, u’/import/software/ci/ansible/library’]
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Apr 2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /import/software/ci/ansible/inventory.ini as it did not pass its verify_file() method
script declined parsing /import/software/ci/ansible/inventory.ini as it did not pass its verify_file() method
auto declined parsing /import/software/ci/ansible/inventory.ini as it did not pass its verify_file() method
yaml declined parsing /import/software/ci/ansible/inventory.ini as it did not pass its verify_file() method
Parsed /import/software/ci/ansible/inventory.ini inventory source with ini plugin
Skipping callback ‘actionable’, as we already have a stdout callback.
Skipping callback ‘counter_enabled’, as we already have a stdout callback.
Skipping callback ‘debug’, as we already have a stdout callback.
Skipping callback ‘dense’, as we already have a stdout callback.
Skipping callback ‘dense’, as we already have a stdout callback.
Skipping callback ‘full_skip’, as we already have a stdout callback.
Skipping callback ‘json’, as we already have a stdout callback.
Skipping callback ‘minimal’, as we already have a stdout callback.
Skipping callback ‘null’, as we already have a stdout callback.
Skipping callback ‘oneline’, as we already have a stdout callback.
Skipping callback ‘selective’, as we already have a stdout callback.
Skipping callback ‘skippy’, as we already have a stdout callback.
Skipping callback ‘stderr’, as we already have a stdout callback.
Skipping callback ‘unixy’, as we already have a stdout callback.
Skipping callback ‘yaml’, as we already have a stdout callback.

PLAYBOOK: main_bgp.yml ******************************************************************************************************
1 plays in main_bgp.yml

PLAY [BGP configuration on KVM hosts] ***************************************************************************************
META: ran handlers

TASK [BGP global configuration] *********************************************************************************************
task path: /import/software/ci/ansible/main_bgp.yml:8
<10.41.16.50> ESTABLISH LOCAL CONNECTION FOR USER: root
<10.41.16.50> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “echo /root/.ansible/tmp/ansible-local-4237_A0At2”&& mkdir “echo /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482898.32-4246-154292164765325” && echo ansible-tmp-1635482898. 32-4246-154292164765325="echo /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482898.32-4246-154292164765325" ) && sleep 0’
Using module file /root/.ansible/collections/ansible_collections/vyos/vyos/plugins/modules/vyos_bgp_global.py
<10.41.16.50> PUT /root/.ansible/tmp/ansible-local-4237_A0At2/tmpvfqtXF TO /root/.ansible/tmp/ansible-local-4237_A0At2/ansibl e-tmp-1635482898.32-4246-154292164765325/AnsiballZ_vyos_bgp_global.py
<10.41.16.50> EXEC /bin/sh -c ‘chmod u+x /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482898.32-4246-154292164 765325/ /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482898.32-4246-154292164765325/AnsiballZ_vyos_bgp_global. py && sleep 0’
<10.41.16.50> EXEC /bin/sh -c ‘/usr/bin/python2 /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482898.32-4246-15 4292164765325/AnsiballZ_vyos_bgp_global.py && sleep 0’
<10.41.16.50> EXEC /bin/sh -c ‘rm -f -r /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482898.32-4246-1542921647 65325/ > /dev/null 2>&1 && sleep 0’
ok: [bgp_vyos] => {
“before”: {
“as_number”: 65535,
“neighbor”: [
{
“address”: “192.168.50.233”,
“remote_as”: 65535
}
]
},
“changed”: false,
“commands”: [],
“invocation”: {
“module_args”: {
“config”: {
“aggregate_address”: null,
“as_number”: 65535,
“bgp_params”: null,
“maximum_paths”: null,
“neighbor”: [
{
“address”: “192.168.50.233”,
“advertisement_interval”: null,
“allowas_in”: null,
“as_override”: null,
“attribute_unchanged”: null,
“capability”: null,
“default_originate”: null,
“description”: null,
“disable_capability_negotiation”: null,
“disable_connected_check”: null,
“disable_send_community”: null,
“distribute_list”: null,
“ebgp_multihop”: null,
“filter_list”: null,
“local_as”: null,
“maximum_prefix”: null,
“nexthop_self”: null,
“override_capability”: null,
“passive”: null,
“password”: null,
“peer_group”: null,
“peer_group_name”: null,
“port”: null,
“prefix_list”: null,
“remote_as”: 65535,
“remove_private_as”: null,
“route_map”: null,
“route_reflector_client”: null,
“route_server_client”: null,
“shutdown”: null,
“soft_reconfiguration”: null,
“strict_capability_match”: null,
“timers”: null,
“ttl_security”: null,
“unsuppress_map”: null,
“update_source”: null,
“weight”: null
}
],
“network”: null,
“redistribute”: null,
“timers”: null
},
“running_config”: null,
“state”: “merged”
}
}
}

TASK [BGP address family configuration] *************************************************************************************
task path: /import/software/ci/ansible/main_bgp.yml:17
<10.41.16.50> ESTABLISH LOCAL CONNECTION FOR USER: root
<10.41.16.50> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “echo /root/.ansible/tmp/ansible-local-4237_A0At2”&& mkdir “echo /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482900.62-4279-140794238493528” && echo ansible-tmp-1635482900. 62-4279-140794238493528="echo /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482900.62-4279-140794238493528" ) && sleep 0’
Using module file /root/.ansible/collections/ansible_collections/vyos/vyos/plugins/modules/vyos_bgp_address_family.py
<10.41.16.50> PUT /root/.ansible/tmp/ansible-local-4237_A0At2/tmpAfCeC2 TO /root/.ansible/tmp/ansible-local-4237_A0At2/ansibl e-tmp-1635482900.62-4279-140794238493528/AnsiballZ_vyos_bgp_address_family.py
<10.41.16.50> EXEC /bin/sh -c ‘chmod u+x /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482900.62-4279-140794238 493528/ /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482900.62-4279-140794238493528/AnsiballZ_vyos_bgp_address _family.py && sleep 0’
<10.41.16.50> EXEC /bin/sh -c ‘/usr/bin/python2 /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482900.62-4279-14 0794238493528/AnsiballZ_vyos_bgp_address_family.py && sleep 0’
<10.41.16.50> EXEC /bin/sh -c ‘rm -f -r /root/.ansible/tmp/ansible-local-4237_A0At2/ansible-tmp-1635482900.62-4279-1407942384 93528/ > /dev/null 2>&1 && sleep 0’
ok: [bgp_vyos] => {
“before”: {},
“changed”: false,
“commands”: [],
“invocation”: {
“module_args”: {
“config”: {
“address_family”: [
{
“afi”: “ipv4”,
“aggregate_address”: null,
“networks”: [
{
“backdoor”: null,
“path_limit”: null,
“prefix”: “172.30.0.0/24”,
“route_map”: null
}
],
“redistribute”: null
},
{
“afi”: “ipv6”,
“aggregate_address”: null,
“networks”: [
{
“backdoor”: null,
“path_limit”: null,
“prefix”: “2001:ef8:1::/48”,
“route_map”: null
}
],
“redistribute”: null
}
],
“as_number”: 65535,
“neighbors”: null
},
“running_config”: null,
“state”: “merged”
}
}
}
META: ran handlers
META: ran handlers

PLAY RECAP ******************************************************************************************************************
bgp_vyos : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

seems that your playbook is okay and ran successfully. By default this ansible module using “merged” state to merge configuration with existing one. Looks like you already have defined configuration on the device and ansible doesn’t make any changes, those this playbook returned the following:

bgp_vyos : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

If you want to replace or override configuration, used “state” and define it as “replaced” or “overridden”.

Yes @e.khudiyev , I have tried both the state ‘replaced’ and ‘overridden’.
Its doesn’t get executed. The same result when merged was being used.

If I understand correctly the original sources located here https://github.com/ansible-collections/vyos.vyos

You can try open an issue.

1 Like