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

Handle None and Blank value for sysctl module #24871

Merged
merged 1 commit into from
May 25, 2017
Merged

Conversation

Akasurde
Copy link
Member

SUMMARY

Fix adds check for values provided by user for
name and value in sysctl module.
While providing name and value as in-line params,
check for blank values

Fixes #20176

Signed-off-by: Abhijeet Kasurde akasurde@redhat.com

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lib/ansible/modules/system/sysctl.py

ANSIBLE VERSION
2.4 devel

Fix adds check for values provided by user for
name and value in sysctl module.
While providing name and value as in-line params,
check for blank values

Fixes ansible#20176

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
@ansibot
Copy link
Contributor

ansibot commented May 21, 2017

cc @davixx
click here for bot help

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bugfix_pull_request core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels May 21, 2017
)

if module.params['name'] is None:
module.fail_json(msg="name can not be None")
Copy link
Contributor

Choose a reason for hiding this comment

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

If the parameter is required, it cannot be None. That's implicit, so this check should not be necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

@dagwieers Thanks for your review. I added this check, because I am facing weird a behaviour, correct me if I am wrong.

Here is demo module which contains name and mode as required parameters.
When I use, ansible-playbook command with following yaml file

- name: sample demo
   demo:
      name:
      mode:

I am getting name and mode as None.

Same case goes with following -

# ansible -m demo -a "name= mode=" localhost

here, I am getting name and mode as "" (blank value)
Let me know, if these behaviours are different from the normal ones. This is only reason, I have added following two checks in sysctl modules, because sysctl was writing blank values to given sysctl.conf file like the issue describes.

Copy link
Contributor

@dagwieers dagwieers May 22, 2017

Choose a reason for hiding this comment

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

Hmm, your first example should not return None values, but empty strings IMO. If you want to assign None-values, you could do that using null. And that would be caught by the required=True.

So if this is true, that seems to be a bug.
You are right, YAML interprets no value as None (or null). And I stand corrected. I doubt a lot of modules handle this correctly as None is the default value (which means the parameter was not provided).

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels May 21, 2017
@Akasurde
Copy link
Member Author

@dagwieers Do I need to do something else to get this PR rolling ?

@gundalow gundalow removed the needs_triage Needs a first human triage before being processed. label May 24, 2017
@bcoca
Copy link
Member

bcoca commented May 24, 2017

So i'm not sure if we should fix this globally (require a value aside from parameter being present) ... should None/''/empty values be significant to module itself?

@jctanner jctanner merged commit 650b5fe into ansible:devel May 25, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
@Akasurde Akasurde deleted the i20176 branch July 13, 2021 04:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sysctl module does not apply kernel parameters for CentOS7
6 participants