Hi all, I am trying to run ansible-playbook to my cisco switch. However, whenever I am trying to use command like “copy run start” or “clear counter” my playbook would just stucked and wont process further.
Can I get your advise on how do I create a playbook that can cater for command that might prompt for user input?
---
- name: Execute Cisco Commands
hosts: cisco_node
gather_facts: false
vars_prompt:
- name: cisco_commands
prompt: "Enter the Cisco commands you want to execute (comma-separated)"
private: no # Set to yes if the commands may contain sensitive information
tasks:
- name: Convert input to list
set_fact:
commands_list: "{{ cisco_commands.split(',') }}"
- name: Run Cisco Commands
ios_command:
commands: "{{ commands_list }}"
register: result
- name: Display Command Outputs
debug:
msg:
- "Input Commands: {{ commands_list }}"
- "Command Outputs: {{ result.stdout_lines }}"
However, it may be a bit difficult to allow users to execute arbitrary commands, since it is obviously inconvenient to have them type in vars_prompt, including prompts and answers
Thanks for the idea, if the command that the user are using is quite different everytime, then I think there will be difficulties maintain a long list of expecting prompt…
I would keep a dictionary of prompt responses based on command, not just have a massive list of responses for any conceivable command. Prompts are way less common then you would think, most use-cases are solved with a couple playbooks, and usually you are simply setting up something else to automate in a more regular good practice (where a prompt wouldn’t be involved).
So for my example the prompt and answer would be a dictionary lookup instead of putting the commands in the task, e.g.
Actually I have found out a way which is by using ios_config to suppress the prompt. However, I found out only prompt from some of the command can be suppressed.