Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssh into switch terminal using ansible #21

Open
Avish34 opened this issue Sep 8, 2022 · 6 comments
Open

ssh into switch terminal using ansible #21

Avish34 opened this issue Sep 8, 2022 · 6 comments

Comments

@Avish34
Copy link

Avish34 commented Sep 8, 2022

Hi,

I wanted a help regarding ssh into switch. When I ssh into switch, it takes me to shell prompt. But I want to reach to terminal using anisble. Please help me out. Also using ssh ansible fails because it's not able to run commands in shell prompt.

Shell prompt:
Screenshot 2022-09-08 at 5 01 58 PM

Ansible error :

Screenshot 2022-09-08 at 5 09 17 PM

Terminal
Screenshot 2022-09-08 at 5 03 28 PM

@Avish34 Avish34 changed the title ssh into switch terminal ssh into switch terminal using ansible Sep 8, 2022
@tchiapuziowong
Copy link
Member

Hi @Avish34 !

Can you please share your playbook and would you be willing to use our AOS-CX Collection instead of the role? We've stopped supporting the role for development and are now primarily focusing on increasing feature breadth and quality on the Collection.

For examples on how to use the collection you can see our workflows Github and here's a link to a specific SSH/CLI module usecase. You may need to remove the variable ansible_python_interpreter from your playbook-

@Avish34
Copy link
Author

Avish34 commented Sep 19, 2022

Hi, @tchiapuziowong. I was hitting some error while using ansible collection, let me post that as well.

The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 147, in run
    res = self._execute()
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 620, in _execute
    self._connection = self._get_connection(cvars, templar)
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 913, in _get_connection
    ansible_playbook_pid=to_text(os.getppid())
  File "/usr/lib/python2.7/site-packages/ansible/plugins/loader.py", line 573, in get
    obj = obj(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/network_cli.py", line 343, in __init__
    self._terminal = terminal_loader.get(self._network_os, self)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/loader.py", line 552, in get
    self._module_cache[path] = self._load_module_source(name, path)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/loader.py", line 530, in _load_module_source
    module = imp.load_source(to_native(full_name), to_native(path), module_file)
  File "/home/avish/.ansible/collections/ansible_collections/arubanetworks/aoscx/plugins/terminal/aoscx.py", line 38
    re.compile(rb"[\r\n]?[\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$")
                                                                         ^
SyntaxError: invalid syntax
fatal: [aoscx_1]: FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""
}

@Avish34
Copy link
Author

Avish34 commented Sep 19, 2022

Playbook :

- hosts: all
  collections:
     - arubanetworks.aoscx
  vars:
    ansible_connection: network_cli
  tasks:
    - name: Execute show commands on the switch
      aoscx_command:
        commands: ['show psm',
        'show version']

@alagoutte
Copy link

alagoutte commented Sep 19, 2022

Hi,

What ansible version ?

The module need Python 3 (don't work with Python 2.x)

@Avish34
Copy link
Author

Avish34 commented Sep 20, 2022

Hi,

What ansible version ?

The module need Python 3 (don't work with Python 2.x)

ansible 2.9.27
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/avish/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

@tchiapuziowong
Copy link
Member

tchiapuziowong commented Sep 20, 2022

@Avish34 I would recommend going through Ansible's documentation on how to upgrade/install to a version that uses Python3
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-and-upgrading-ansible

Once that's done you should follow these instructions for installing the collection and the python requirements:
https://github.com/aruba/aoscx-ansible-collection#installation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants