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

document how to address devices via serial console #20

Closed
PeterNerlich opened this issue Apr 23, 2020 · 11 comments
Closed

document how to address devices via serial console #20

PeterNerlich opened this issue Apr 23, 2020 · 11 comments

Comments

@PeterNerlich
Copy link

In the documentation, when searching for "console" or "expect", the only hits are in the README, which speaks of this being part of the feature set. But how to address these devices (especially since Ansible itself usually only uses domains or IP addresses) is not explained.

@greenpau
Copy link
Owner

@PeterNerlich , for this you would need socat.

The following command link serial port ttyXX to a localhost TCP port, e.g. 3231. It would similar to this. You would need to tinker a bit 😄

socat /dev/ttyXX,raw,echo=0,crnl TCP4:localhost:3231

Then, you will use the following config in hosts

ny-fw02-via-console os=cisco_asa host_overwrite=127.0.0.1 host_protocol=telnet host_port=3231

Hope this explains it.

@PeterNerlich
Copy link
Author

Okay, thank you.

I'm trying to look into ways of addressing a few currently unsupported switches/firewalls by MOXA and HIRSCHMANN. I don't know if CISCO does the same or not, but they offer an interactive serial console which is clearly not made for easy automated interfacing. Can I expect this to be as easy as to add them as a system type and specify the command set and return format or does this currently rely on features unlikely to exist with a conventional interactive serial console?

@greenpau
Copy link
Owner

greenpau commented Apr 23, 2020

interactive serial console which is clearly not made for easy automated interfacing

@PeterNerlich , I think in that case please use generic_linux device type.

Can I expect this to be as easy as to add them as a system type and specify the command set and return format or does this currently rely on features unlikely to exist with a conventional interactive serial console?

You would need to tinker with it and look at debug logs. Set "debug=yes" in a playbook, e.g.

---
- name: generic data collection
  hosts:
  - ny-fw01-via-console
  gather_facts: no
  tasks:
  - name: data collection from three network devices
    action: ndmtk output="/tmp/ndmtk-%Y%m%d%H%M%S" debug=yes no_host_key_check=yes on_error=continue

@greenpau
Copy link
Owner

@PeterNerlich , also ... you always can modify https://github.com/greenpau/ndmtk/blob/master/ndmtk/plugins/action/ndmtk.j2 directly on your OS to get what you need.

You will have to dive into the intricacies of expect! 😄

@greenpau
Copy link
Owner

@PeterNerlich , the device types are being used here. You need device type generic_linux.

if { $host_operating_system == "paloalto_panos" || $host_operating_system == "junos_qfx" || $host_operating_system == "junos_srx" || \
$host_operating_system == "junos_mx" || \
$host_operating_system == "citrix_netscaler" || $host_operating_system == "generic_linux" || \
$host_operating_system == "opengear_linux" || $host_operating_system == "cisco_ironport" } {
if { $host_operating_system == "paloalto_panos" } {
puts $session_log "timestamp='[exec date]' transaction_id='$transaction_id' msg='currently in PAN-OS Operational Mode'";
}
if { $host_operating_system == "junos_qfx" || $host_operating_system == "junos_srx" || $host_operating_system == "junos_mx" } {
puts $session_log "timestamp='[exec date]' transaction_id='$transaction_id' msg='currently in Junos OS Operational Mode'";
}
if { $host_operating_system == "citrix_netscaler" } {
puts $session_log "timestamp='[exec date]' transaction_id='$transaction_id' msg='currently in Operational Mode'";
}
if { $host_operating_system == "generic_linux" || $host_operating_system == "opengear_linux" } {
puts $session_log "timestamp='[exec date]' transaction_id='$transaction_id' msg='currently in Linux shell'";
}
if { $host_operating_system == "cisco_ironport" } {
puts $session_log "timestamp='[exec date]' transaction_id='$transaction_id' msg='currently in IronPort AsyncOS shell'";
}

For this device type, I perform extra steps.

if { $host_operating_system == "generic_linux" || $host_operating_system == "opengear_linux" } {
expect -re "\r\n|\n|\r";
expect -re $;

@PeterNerlich
Copy link
Author

Whoa, thank you very much! That's a lot of pointers already. I expect to really start digging into this in the next week. If you are fine with providing further assistence on things I deem ndmtk-related, I'll write you again, but not in this issue. Thank you again, I'm kind of getting excited now 😁

@greenpau
Copy link
Owner

If you are fine with providing further assistence on things I deem ndmtk-related,

@PeterNerlich , sure! just ping me here! I will close this issue, but you can comment/ask question below.

Start here: https://www.busindre.com/_media/exploring_expect.pdf

@PeterNerlich
Copy link
Author

@greenpau Didn't go as fast as I wished, but now I'm trying to do things again and I hit a wall.

Executing the playbook from the README gives me this error: http://termbin.com/jwop
It seems very weird, since it says invalid token while pointing at the file mode... Do you as the module author have an idea before I try to poke around and create more problems? 😁

@greenpau
Copy link
Owner

Do you as the module author have an idea before I try to poke around and create more problems?

@PeterNerlich , notice the following line:

  File "/home/pi/ndmtk/lib/python3.5/site-packages/ansible/plugins/action/ndmtk.py", line 3190
    os.makedirs(commit_dir, mode=0700);

It is a python error: I would say would need to modify line 3190 of /home/pi/ndmtk/lib/python3.5/site-packages/ansible/plugins/action/ndmtk.py

os.makedirs(commit_dir, mode=0o700, exist_ok=True)

Reference: See https://stackoverflow.com/questions/1837874/invalid-token-when-using-octal-numbers

@greenpau
Copy link
Owner

@PeterNerlich , feel free asking questions! 😄

@greenpau
Copy link
Owner

Opened #21 to fix it at some point.

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

2 participants