Skip to content

Conversation

@vnitinv
Copy link
Contributor

@vnitinv vnitinv commented Jun 19, 2017

user can now pass ignore_warning as per https://github.com/Juniper/py-junos-eznc/blob/master/lib/jnpr/junos/utils/config.py#L336

  tasks:
    - name: install config to device
      junos_install_config:
        host: "{{ inventory_hostname }}"
        ignore_warning: True
        file: xxxx.set
  tasks:
    - name: install config to device
      junos_install_config:
        host: "{{ inventory_hostname }}"
        ignore_warning: "statement not found"
        file: xxxx.set
  tasks:
    - name: install config to device
      junos_install_config:
        host: "{{ inventory_hostname }}"
        ignore_warning:
          - "statement not found"
          - "testing"
        file: xxxx.set

Copy link
Contributor

@stacywsmith stacywsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to also add a check to ensure that PyEZ >= 2.1.1 is used when ignore_warning is specified.

I suggest just simplifying the PyEZ version check to always requiring PyEZ >= 2.1.1

logging.error(msg)
module.fail_json(msg=msg)

if args['ignore_warning'] in BOOLEANS + ["True", "False"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ansible boolean values are normally case-insensitive, but this is not. Suggest changing to:

if str(args['ignore_warning']).lower() in BOOLEANS + ["true", "false"]:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not defined ignore_warning as a string for few reasons. With the older version of Ansible type will be taken care of. So if I pass in Boolean, string, list it will remain so.
Do you suggest me to make ignore_warning type defined as string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stacywsmith I have tested all possible scenarios and dont see any failure case. Can you help me identifying the condition in which we would require this?


if args['ignore_warning'] in BOOLEANS + ["True", "False"]:
args['ignore_warning'] = module.boolean(module.params['ignore_warning'])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to do additional arg type checking here to ensure that args['ignore_warning'] is a string type of list of string types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didnt do that for few reason:
older version of ansible will have it as list itself. with >=2.3 it will be string and in PyEZ we do regular expression check where we loop with all rpc-warning and check if that matches any on in the list.
In this case it will just search/match the warnings in the string of list (for ex "['statment not found', 'xyz']"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stacywsmith converting string (of list) to list now.

warning message. If the value is a string, it will ignore
warning(s) if the message of each warning matches the string. If
the value is a list of strings, ignore warning(s) if the message of
each warning matches at least one of the strings in the list.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a line stating:

All warning messages produced when loading, diffing, checking, or committing the configuration are checked against ignore_warning. 

Then add code to pass ignore_warning value when diffing or checking the config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we should do it for diff as I never diff function is PyEZ itself doesnt support that and also I never encountered diff giving rpc-error (with severity Warning). I dont see any reason too for getting such error from diff.
commit_check we can do, but for this function PyEZ don't support for now. So we cant do changes as of today.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we have encountered diff returning a warning.
https://github.com/Juniper/py-junos-eznc/blob/master/lib/jnpr/junos/utils/config.py#L228-L233

We did that before we added ignore_warning to PyEZ.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stacywsmith Even if we want to do ignore_warning support for diff function then we first need to change the PyEZ diff function itself. Right now it won't accept any extra parameters.

https://github.com/Juniper/py-junos-eznc/blob/master/lib/jnpr/junos/utils/config.py#L208

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vnitinv Yes. Agreed. If we need ignore_warning support for diff, we can add it at a future point.

@artcrime
Copy link

Hi,
when will this change be commited? We have issues pushing a configuration to a SRX300 with Junos 15.1 cause a master password is set an the passwords in our .set configuration are not complex enough. So the ansible module will not commit the config because of the warnings.

@vnitinv
Copy link
Contributor Author

vnitinv commented Jul 13, 2017

@stacywsmith can you please review latest changes to this pull request. We need to check why Ravelo is now failing with ConnectUnknownHostError

module.fail_json(msg=msg)

logging.info("connecting to host: {0}@{1}:{2}".format(args['user'], args['host'], args['port']))
if args['ignore_warning'] in BOOLEANS + ["True", "False"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is to match the exact same things that Ansible would normally interpret as a boolean.

From http://docs.ansible.com/ansible/YAMLSyntax.html:

Ansible doesn’t really use these too much, but you can also specify a boolean value (true/false) in several forms:

create_key: yes
needs_agent: no
knows_oop: True
likes_emacs: TRUE
uses_cvs: false

The current code would not match the string TRUE, for example.
The Ansible code for determining boolean values does a case-insensitive match on the boolean values. You can see this here:
https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py#L2046-L2057

That's why I'm suggesting this line should be:

if str(args['ignore_warning']).lower() in BOOLEANS + "none":

That should match the same values which module.boolean() will actually convert into a boolean value.

Copy link
Contributor Author

@vnitinv vnitinv Jul 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stacywsmith , I have done the below changes only

if str(args['ignore_warning']).lower() in BOOLEANS:

Why is + "none" is required here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was recommending + "none" because module.booleans() accepts None as a valid value. However, module.booleans() just returns the unmodified None value in that case, so you are correct that it's not necessary. I'm now fine with the code as it is.

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

Successfully merging this pull request may close these issues.

3 participants