My network appliance needs a non_root ssh login, followed by an “enable” command, followed by an “su” command, followed by the root password. Here’s the sequence for my root login:
$ ssh admin@10.0.34.210
admin@10.0.34.210's password: ...
My_Device>
My_Device>enable
My_Device#
My_Device#su
Password: ......
[root@My_Hostname:/tmp]$
[root@My_Hostname:/tmp]$ exit
logout
My_Device#
My_Device#exit
My_Device>
My_Device>logout
Connection to 10.0.34.210 closed.
$
I am able to get non-root shell (CLI) commands working, but not able to get a shell for root shell commands. Here the playbook:
- name: Test_Playbook
hosts: all
gather_facts: false #Set to false, since our device does not have python.
vars:
ansible_connection: network_cli
ansible_host_key_checking: false
ansible_user: admin
ansible_password: "{{ admin_password }}"
ansible_network_os: ios
ansible_become: true
ansible_become_method: su #Using "su" since "enable" only enters privileged mode, but does not become root.
ansible_become_password: "{{ su_password }}" #Comment out if "enable" is used, since it does not need password.
ansible_network_become_errors: warn #Set to warn, since our CLI does not have "show privilege".
tasks:
- name: Test_CLI
tags: cli
register: results_test
ios_command:
commands:
- show boot
- name: Debug_CLI
tags: cli
debug:
var: results_test.stdout_lines
- name: Test_Root
tags: root
register: results_root
cli_command:
command: id
- name: Debug_Root
tags: root
debug:
var: results_root.stdout_lines
Here’s the output:
$ ansible-playbook -i 10.0.34.210, -e admin_password=... -e su_password=...... try.yaml
PLAY [Test_Playbook] ******************************************************************
TASK [Test_CLI] ***********************************************************************
ok: [10.0.34.210]
TASK [Debug_CLI] **********************************************************************
[WARNING]: on_become: privilege escalation failed
ok: [10.0.34.210] => {
"results_test.stdout_lines": [
[
"Boot from : disk\tpartition 1 ",
"Next Boot : disk\tpartition 1"
]
]
}
TASK [Test_Root] **********************************************************************
fatal: [10.0.34.210]: FAILED! => {"changed": false, "msg": \
"id\r\n ^\r\n% Invalid input detected at '^' marker\r\nMy_Device#"}
PLAY RECAP ****************************************************************************
10.0.34.210 : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
$