diff --git a/lib/ansible/modules/network/eos/eos_eapi.py b/lib/ansible/modules/network/eos/eos_eapi.py index c3ae14f3339..541b104a87d 100644 --- a/lib/ansible/modules/network/eos/eos_eapi.py +++ b/lib/ansible/modules/network/eos/eos_eapi.py @@ -260,11 +260,17 @@ def map_obj_to_commands(updates, module, warnings): else: add('protocol unix-socket') + if needs_update('state') and not needs_update('vrf'): + if want['state'] == 'stopped': + add('shutdown') + elif want['state'] == 'started': + add('no shutdown') + if needs_update('vrf'): add('vrf %s' % want['vrf']) - - if needs_update('state'): + # switching operational vrfs here + # need to add the desired state as well if want['state'] == 'stopped': add('shutdown') elif want['state'] == 'started': diff --git a/test/units/modules/network/eos/test_eos_eapi.py b/test/units/modules/network/eos/test_eos_eapi.py index 5ef9a3b14f2..dfb4e83f4a1 100644 --- a/test/units/modules/network/eos/test_eos_eapi.py +++ b/test/units/modules/network/eos/test_eos_eapi.py @@ -134,6 +134,11 @@ class TestEosEapiModule(TestEosModule): commands = ['management api http-commands', 'vrf test', 'no shutdown'] self.start_unconfigured(changed=True, commands=commands) + def test_eos_eapi_change_from_default_vrf(self): + set_module_args(dict(vrf='test')) + commands = ['management api http-commands', 'vrf test', 'no shutdown'] + self.start_configured(changed=True, commands=commands) + def test_eos_eapi_vrf_missing(self): set_module_args(dict(vrf='missing')) self.start_unconfigured(failed=True)