Minor rework of pamd module. Fixed some documentation. (#19758)

* Minor rework.  Fixed some documentation.

* Requested changes in the case the arg is unicode
This commit is contained in:
Ken Evensen 2017-01-05 18:48:24 -05:00 committed by Matt Davis
commit 99e19ad617

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import string_types
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.pycompat24 import get_exception
DOCUMENTATION = """ DOCUMENTATION = """
@ -74,9 +75,9 @@ options:
missing from the existing rule. Furthermore, if the module argument missing from the existing rule. Furthermore, if the module argument
takes a value denoted by '=', the value will be changed to that specified takes a value denoted by '=', the value will be changed to that specified
in module_arguments. in module_arguments.
insert: state:
required: false required: false
default: none default: updated
choices: choices:
- updated - updated
- before - before
@ -133,7 +134,8 @@ EXAMPLES = """
type: auth type: auth
control: required control: required
module_path: pam_faillock.so module_path: pam_faillock.so
new_type: auth new_control=sufficient new_type: auth
new_control=sufficient
new_module_path: pam_faillock.so new_module_path: pam_faillock.so
state: after state: after
@ -263,7 +265,6 @@ class PamdService(object):
self.fname = self.path + "/" + self.name self.fname = self.path + "/" + self.name
self.preamble = [] self.preamble = []
self.rules = [] self.rules = []
try: try:
for line in open(self.fname, 'r'): for line in open(self.fname, 'r'):
if line.startswith('#') and not line.isspace(): if line.startswith('#') and not line.isspace():
@ -380,11 +381,14 @@ def remove_module_arguments(service, old_rule, module_args):
result = {'action': 'args_absent'} result = {'action': 'args_absent'}
changed = False changed = False
change_count = 0 change_count = 0
if isinstance(module_args, ansible.module_utils.six.string_types):
module_args = module_args.split(' ')
for rule in service.rules: for rule in service.rules:
if (old_rule.rule_type == rule.rule_type and if (old_rule.rule_type == rule.rule_type and
old_rule.rule_control == rule.rule_control and old_rule.rule_control == rule.rule_control and
old_rule.rule_module_path == rule.rule_module_path): old_rule.rule_module_path == rule.rule_module_path):
for arg_to_remove in module_args.split(): for arg_to_remove in module_args:
for arg in rule.rule_module_args: for arg in rule.rule_module_args:
if arg == arg_to_remove: if arg == arg_to_remove:
rule.rule_module_args.remove(arg) rule.rule_module_args.remove(arg)
@ -401,11 +405,14 @@ def add_module_arguments(service, old_rule, module_args):
result = {'action': 'args_present'} result = {'action': 'args_present'}
changed = False changed = False
change_count = 0 change_count = 0
if isinstance(module_args, ansible.module_utils.six.string_types):
module_args = module_args.split(' ')
for rule in service.rules: for rule in service.rules:
if (old_rule.rule_type == rule.rule_type and if (old_rule.rule_type == rule.rule_type and
old_rule.rule_control == rule.rule_control and old_rule.rule_control == rule.rule_control and
old_rule.rule_module_path == rule.rule_module_path): old_rule.rule_module_path == rule.rule_module_path):
for arg_to_add in module_args.split(' '): for arg_to_add in module_args:
if "=" in arg_to_add: if "=" in arg_to_add:
pre_string = arg_to_add[:arg_to_add.index('=')+1] pre_string = arg_to_add[:arg_to_add.index('=')+1]
indicies = [i for i, arg indicies = [i for i, arg
@ -450,22 +457,22 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
name=dict(required=True), name=dict(required=True, type='str'),
type=dict(required=True, type=dict(required=True,
choices=['account', 'auth', choices=['account', 'auth',
'password', 'session']), 'password', 'session']),
control=dict(required=True), control=dict(required=True, type='str'),
module_path=dict(required=True), module_path=dict(required=True, type='str'),
new_type=dict(required=False, new_type=dict(required=False,
choices=['account', 'auth', choices=['account', 'auth',
'password', 'session']), 'password', 'session']),
new_control=dict(required=False), new_control=dict(required=False, type='str'),
new_module_path=dict(required=False), new_module_path=dict(required=False, type='str'),
module_arguments=dict(required=False), module_arguments=dict(required=False, type='list'),
state=dict(required=False, default="updated", state=dict(required=False, default="updated",
choices=['before', 'after', 'updated', choices=['before', 'after', 'updated',
'args_absent', 'args_present']), 'args_absent', 'args_present']),
path=dict(required=False, default='/etc/pam.d') path=dict(required=False, default='/etc/pam.d', type='str')
), ),
supports_check_mode=True supports_check_mode=True
) )