# Setting VTP primary using cisco.ios.ios\_command module

**URL:** <https://forum.ansible.com/t/setting-vtp-primary-using-cisco-ios-ios-command-module/4443>\
**Category:** Get Help\
**Tags:** cisco, network\
**Created:** [March 19, 2024, 2:19am UTC](https://forum.ansible.com/t/setting-vtp-primary-using-cisco-ios-ios-command-module/4443 "2024-03-19T02:19:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdetwiler16](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jdetwiler16](https://forum.ansible.com/u/jdetwiler16)\
**Post date:** [March 19, 2024, 2:19am UTC](https://forum.ansible.com/t/setting-vtp-primary-using-cisco-ios-ios-command-module/4443/1 "2024-03-19T02:19:08Z")

</div>

Hi all! I’m somewhat new to Ansible and looking for some help getting the Cisco ios\_command module to work in my favor to set a device as VTP primary in VTPv3. I’ve tried seemingly every combination under the sun I can think of to get this to work and no dice. I have the test set up as the below targeting a device that is not VTP primary:

```auto
    - name: Make Device VTP Primary 
      cisco.ios.ios_command:
        commands:
        - command: 'vtp primary'
          prompt:
            - Enter VTP Password
            - No conflicting
          answer:
            - "{{ passwd_vtp }}"
            - confirm
      vars:
        ansible_command_timeout: 240

```

When I run it like this, the below is the error I get out in Ansible:

```auto
fatal: [HOSTNAME]: FAILED! => changed=false 
  msg: 'cli prompt is not identified from the last received response window: b''\r\nNo conflicting VTP3 devices found.\r\nDo you want to continue? [confirm]'''

```

In the actual command line entering manually, it would look like this:

```auto
HOSTNAME#vtp primary
This system is becoming primary server for feature vlan
Enter VTP Password:
No conflicting VTP3 devices found.
Do you want to continue? [confirm]
HOSTNAME#

```

As you can see, it’s reading and accepting my VTP password for the first prompt, but whatever I try for the second prompt, I get that same error, like it’s not matching on the regex in the prompt line I’m entering.

For additional reference, this is what our contractor discovered from the web when first starting this adventure, but it throws a VTP password mismatch error:

```auto
      cisco.ios.ios_command:
        commands:
        - command: 'vtp primary'
          prompt:
            - 'This system is becoming primary server for feature vlan'
            - 'Enter VTP Password\:'
            - 'No conflicting VTP3 devices found.'
            - 'Do you want to continue? \[confirm\]'
          answer:
            - ''
            - '{{ passwd.vtp }}'
            - ''
            - '\n'

```

Has anyone ever encountered this or have any suggestions? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [March 19, 2024, 11:09pm UTC](https://forum.ansible.com/t/setting-vtp-primary-using-cisco-ios-ios-command-module/4443/2 "2024-03-19T23:09:12Z")

</div>

I’m not in the office now. So, I cannot mock this up to try it out. Below is what I would try if I were in the office.

The [doc site](https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_command_module.html) for the module doesn’t go into detail about the prompt/answer capabilities, but it seems like they are trying to mimic the expect module.

Try this:

```yaml
    - name: Make Device VTP Primary 
      cisco.ios.ios_command:
        commands:
        - command: 'vtp primary'
          prompt:
            - Enter VTP Password
            - .*confirm.*
          answer:
            - "{{ passwd_vtp }}"
            - "\r"
      vars:
        ansible_command_timeout: 240

```

The format of the prompts in the examples implies that the prompt string are regular expressions. So, the special characters in and new lines might be messing with the behavior you are expecting.

Also, the examples only have one prompt per command. So, it could be that the module is only expecting you to use one follow up prompt per command.

If that’s the case, try this:

```yaml
    - name: Make Device VTP Primary 
      cisco.ios.ios_command:
        commands:
        - command: 'vtp primary'
          prompt: Enter VTP Password
          answer: "{{ passwd_vtp }}"
        - command: "confirm"
      vars:
        ansible_command_timeout: 240

```

The last ditch effort is to cram all of the inputs into a single command and hope the input queue of the device properly passes them to the interactive prompts.

```yaml
    - name: Make Device VTP Primary 
      cisco.ios.ios_command:
        commands: "vtp primary\r{{ passwd_vtp }}\rconfirm\r"
      vars:
        ansible_command_timeout: 240

```

---

<div class="post-metadata">

**Author:** ![jdetwiler16](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jdetwiler16](https://forum.ansible.com/u/jdetwiler16)\
**Post date:** [March 20, 2024, 1:41am UTC](https://forum.ansible.com/t/setting-vtp-primary-using-cisco-ios-ios-command-module/4443/3 "2024-03-20T01:41:30Z")

</div>

Thanks for the help, Dustin!

Yes, I did refer to the module documentation rather thoroughly, but like you said it doesn’t really address multiple prompts. HOWEVER, this does: [Working with command output and prompts in network modules — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/network/user_guide/network_working_with_command_output.html). Assuming this is operating in the same way as _ansible.netcommon.cli\_command_ or even using it in the background, then it SHOULD work as we tried originally. However, to your point, I think the new line characters and lack of a prompt from those is messing with things, as you said.

I tried the first option you mentioned and it gave the same “cli prompt is not identified” error I mentioned. The second option failed also, but with _msg: Failed to write to ssh channel_, which I’m going to guess is something to do with the fact that it’s expecting a command prompt instead of some other prompt…? The last one just threw a good old syntax error because the module just slammed it in as one big string instead of parsing the /r into a return line.

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [March 20, 2024, 1:52am UTC](https://forum.ansible.com/t/setting-vtp-primary-using-cisco-ios-ios-command-module/4443/4 "2024-03-20T01:52:59Z")

</div>

Until I get a chance to get in office and play a bit, the only other thing I could say is try the last one again with `\n` instead of `\r`.

---

<div class="post-metadata">

**Author:** ![jdetwiler16](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jdetwiler16](https://forum.ansible.com/u/jdetwiler16)\
**Post date:** [March 20, 2024, 2:48am UTC](https://forum.ansible.com/t/setting-vtp-primary-using-cisco-ios-ios-command-module/4443/5 "2024-03-20T02:48:28Z")

</div>

VICTORY! It ended up having to do with the check\_all setting from that _ansible.netcommon.cli\_command_ module I mentioned. I noticed in there it referenced that had to be true with multiple prompts and having that set or else it would cause each prompt to be answered by the first answer every time. It seems like it actually may do a little more than that in reality though. Thanks again for the help and guidance, Dustin!

Here’s the final working code fragment:

```auto
- name: Make Device VTP Primary 
  cisco.ios.ios_command:
    commands:
    - command: 'vtp primary'
      check_all: true
      prompt: 
        - Enter VTP Password
        - No conflicting
      answer:
        - "{{ passwd_vtp }}"
        - y
  vars:
    ansible_command_timeout: 90

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 19, 2024, 2:48am UTC](https://forum.ansible.com/t/setting-vtp-primary-using-cisco-ios-ios-command-module/4443/6 "2024-04-19T02:48:41Z")

</div>

Closed on April 19, 2024, 2:48am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
