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

Added 'newline_char' option to specify the character to be sent after… #52753

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
4 participants
@bknight-nitel
Copy link

bknight-nitel commented Feb 21, 2019

… each command

Added 'exit_cmd' option to sign out of the device

SUMMARY

I am working on a device that does not use the UNIX convention where the linefeed character is the line terminator; instead it uses CR. (The LF character acts as an "abort action", similar to ^U on a UNIX system, where all characters typed into the terminal line left of the cursor are deleted.) I need a way to specify the newline character.

In addition, the unit does not recognize 'exit\r' as a valid command to terminate the session; only 'logout' is accepted.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

plugins/action/telnet.py

ADDITIONAL INFORMATION
  • Added a new variable, newline_char
  • newline_char is initialized from self._task.args.get('newline_char') so that it can be specified in playbooks. Default is b"\n"
  • Removed the hardcoded b"\n" string within the telnet.py module, replaced with the variable
  • Added a second new variable, exit_cmd
  • exit_cmd is initialized from self._task.args.get('exit_cmd') so that it can be specified in playbooks. Default is b"exit"
  • Removed the hardcoded b"exit" string within the telnet.py module, replaced with the variable

Before the change, here is what I would see in debug output when I connect to the device. The device would backspace over my line, and the change would not take:

TASK [perle-common : Set server name] ****************************************************
task path: /etc/ansible/roles/perle-common/tasks/main.yml:4
>>> set server name MTS1.CPELab
<<< set server name MTS1.CPELab
changed: [MTS1.CPELab] => {
    "changed": true, 
    "output": [
        "set server name MTS1.CPELab\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\rSCS32# "
    ]
}

After I made the changes in telnet.py, and updated my playbook to include newline_char: "\r" in my job step, I now see better results, and the server's name has been changed:

TASK [perle-common : Set server name] ****************************************************
task path: /home/bknight/ansible/ansible-config/roles/perle-common/tasks/main.yml:4
>>> set server name MTS1.CPELab
<<< set server name MTS1.CPELab
changed: [MTS1.CPELab] => {
    "changed": true, 
    "output": [
        "set server name MTS1.CPELab\r\nSCS32# "
    ]
}

Please be gentle, this is my first time ever forking a project, contributing a fix, creating a pull request, etc etc. Thanks.

Added 'newline_char' option to specify the character to be sent after…
… each command

Added 'exit_cmd' option to sign out of the device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.