ansible-collections / cisco.iosxr

Ansible Network Collection for Cisco IOSXR
GNU General Public License v3.0
69 stars 48 forks source link

iosxr_banner module issue #77

Open sbanswar opened 4 years ago

sbanswar commented 4 years ago

The playbbok get timeout with multiple lines but if have only 2 lines it works, any pointer how to fix even increasing timeout doesn't make any different.

Have tried both Login & Motd options

Ansible Version - 2.8.4

name: Testing Cisco ASR9006 hosts: HOSTNAME gather_facts: no connection: netwotk_cli

tasks:

name: Configure the Login banner iosxr_banner: banner: login text: | line 1 line 2 line 3 state: present @rohitthakur2590 rohitthakur2590 self-assigned this on Jul 1 @rohitthakur2590

Contributor rohitthakur2590 commented on Jul 8 @sbanswar could you try with latest release as It works fine, following are the examples to configure timers

export ANSIBLE_PERSISTENT_CONNECT_TIMEOUT=60 [persistent_connection] command_timeout = 100 connect_timeout = 100 connect_retry_timeout = 100 https://docs.ansible.com/ansible/latest/reference_appendices/config.html @rohitthakur2590 rohitthakur2590 closed this on Jul 8 @sbanswar

Author sbanswar commented 9 days ago Hi Rohit,

What version are you suggesting , using 2.8.4? Tried with shared timers, still same error. @sbanswar

Author sbanswar commented 7 days ago In addition, I don't think it's an issue with timeout, looks module doesn't able to understand the end of line hence throwing timeout error.

xorrkaz commented 4 years ago

Yeah, I'm seeing this, too. What happens is the banner string is converted to repr() format, and this is tripping up the IOS-XR shell into not seeing the trailing '. What then happens is the CLI hangs waiting for the multiline termination character.

If I change the {0!r} on line 132 in the module to just {0}, and then make sure my banner has delimiters for the first and last characters (e.g., I used '@' as I didn't use '@' anywhere else in my banner), then it works in both network_cli and netconf modes.

sbanswar commented 4 years ago

Thanks a lot, it worked. Only concern content doesn't reflect in format, it comes in a single row. Any idea how to set it? ** line1 line2 line3**

Where I am looking something


line1 line2 line3


sbanswar commented 4 years ago

No problem, looks fine now :)

sean-m-sullivan commented 4 years ago

@sbanswar can you post how you got the multiline working?

xorrkaz commented 4 years ago

The solution in my PR preserved the multiple lines in my tests provided I used the correct YAML '|' character to avoid folding. Was the PR code not working for you?

sean-m-sullivan commented 4 years ago

I tried

- name: Push banners on Tor
  cisco.iosxr.iosxr_banner:
    banner: motd
    text: |
      testing line1
      testing line 2
      testing line 3
      Ceci est un test
    state: present

and it is single line

xorrkaz commented 4 years ago

My code now requires a delimiter character. So if you're using the PR code, try putting a @ at the beginning and end of the banner text.

sean-m-sullivan commented 4 years ago

I forgot that, and then was using the non updated version, Its working as expected now.

refriedjello commented 4 years ago

I am having issues with the banner module as well.

1) It doesn't properly escape characters in the string like '/' - the banner module for NXOS handles this fine 2) It doesn't handle multi-line formatting properly. Trying several methods always results in a single line banner 3) It doesn't handle more than 3 lines.

The error for 3 is "timeout value 30 seconds reached while trying to send command" and increasing the timeout does not help. It's not an issue of the command taking too long to complete.

Here are examples for 3:

### full banner - NO work
- name: "banner - configure"
  cisco.iosxr.iosxr_banner:
    banner: login
    text: |
      This information system is  the property of  Company.  It is for authorized use
      only. By using this   system, all users acknowledge notice of, and agree to comply
      with,  Company  policies.  Unauthorized  or  improper  use  of this  system may
      result in administrative disciplinary action, civil charges or criminal penalties,
      and or termination. By  continuing to use this system you  indicate your awareness
      of and consent to these terms and  conditions of use. LOG  OFF  IMMEDIATELY if you
      do not agree to the conditions stated in this warning.
    state: present
### partial banner - WORKS but single-line
- name: "banner - configure"
  cisco.iosxr.iosxr_banner:
    banner: login
    text: |
      This information system is  the property of  Company.  It is for authorized use
      only. By using this   system, all users acknowledge notice of, and agree to comply
      with,  Company  policies.  Unauthorized  or  improper  use  of this  system may
    state: present
### partial banner - one more line - NO work, timeout
- name: "banner - configure"
  cisco.iosxr.iosxr_banner:
    banner: login
    text: |
      This information system is  the property of  Company.  It is for authorized use
      only. By using this   system, all users acknowledge notice of, and agree to comply
      with,  Company  policies.  Unauthorized  or  improper  use  of this  system may
      with,  Company  policies.  Unauthorized  or  improper  use  of this  system may
    state: present
xorrkaz commented 4 years ago

If you use the latest code in Git, you'll need to use your own delimiter, but the banner should work. Pull the latest code, and then try something like:


- name: "banner - configure"
  cisco.iosxr.iosxr_banner:
    banner: login
    text: |
      @This information system is  the property of  Company.  It is for authorized use
      only. By using this   system, all users acknowledge notice of, and agree to comply
      with,  Company  policies.  Unauthorized  or  improper  use  of this  system may
      with,  Company  policies.  Unauthorized  or  improper  use  of this  system may@
    state: present
refriedjello commented 4 years ago

If you use the latest code in Git, you'll need to use your own delimiter, but the banner should work. Pull the latest code, and then try something like:

That does work, thank you for that. Unfortunately it's not 100% compatible with the NXOS banner module. There, I am able to make a play like so:

- name: "{{ play_name }} - configure"
  cisco.iosxr.iosxr_banner:
    banner: motd
    text: "{{ banner_motd }}"
    state: present

Where banner_motd is a pre-loaded variable via these declarations:

banner_motd_file: '/etc/ansible/netdata/services/banner_motd.txt'
banner_motd: "{{ lookup('file', banner_motd_file) }}"

And the contents of banner_motd.txt is just a standard text file with line breaks and some special characters. Much more scalable to re-use same banner file across different OS vendors like that.

So if anyone was curious at taking another stab at improving this module, may just want to more or less copy what has been done for the Cisco NXOS banner module.

jorgenspange commented 1 year ago

Good day,

See that this issue has not been done anything with for a while. Like @refriedjello I've done it the way he has done both for cisco.ios and cisco.nxos.

Got it working for cisco.iosxr by doing this:

- name: configuration_cisco.iosxr.iosxr | Set motd banner.
  cisco.iosxr.iosxr_banner:
    banner: motd
    text: |
      #
      {{ lookup('file', 'banner.cfg') }}
      #
    state: present

Instead of this:

- name: configuration_cisco.iosxr.iosxr | Set motd banner.
  cisco.iosxr.iosxr_banner:
    banner: motd
    text: "{{ lookup('file', 'banner.cfg') }}"
    state: present
  notify: Save ios.

Would be nice if the delimiter character was incorporated in the module.

Another problem with the module is that banner exec is not a viable method even though it does exist on iosxr:

RP/0/RSP0/CPU0:ASR9901(config)#banner ?
  LINE            c banner-text c, where 'c' is a delimiting character
  exec            Set EXEC process creation banner
  incoming        Set incoming terminal line banner
  login           Set login banner
  motd            Set Message of the Day banner
  prompt-timeout  Set Message for login authentication timeout
  slip-ppp        Set Message for SLIP/PPP

Could someone look into this?