mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
pamd: fix issue with trailing commas in module_arguments
This commit is contained in:
parent
7f92741c3d
commit
8724ff3eae
2 changed files with 68 additions and 29 deletions
|
@ -1,9 +1,10 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# (c) 2016, Kenneth D. Evensen <kevensen@redhat.com>
|
||||
# (c) 2017, Kenneth D. Evensen <kevensen@redhat.com>
|
||||
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
|
@ -62,7 +63,8 @@ options:
|
|||
'args_present' any args listed in module_arguments are added if
|
||||
missing from the existing rule. Furthermore, if the module argument
|
||||
takes a value denoted by '=', the value will be changed to that specified
|
||||
in module_arguments.
|
||||
in module_arguments. Note that module_arguments is a list. Please see
|
||||
the examples for usage.
|
||||
state:
|
||||
default: updated
|
||||
choices:
|
||||
|
@ -157,7 +159,7 @@ EXAMPLES = """
|
|||
name: system-auth
|
||||
type: session control='[success=1 default=ignore]'
|
||||
module_path: pam_succeed_if.so
|
||||
module_arguments: 'crond quiet'
|
||||
module_arguments: crond,quiet
|
||||
state: args_absent
|
||||
|
||||
- name: Ensure specific arguments are present in a rule
|
||||
|
@ -166,7 +168,28 @@ EXAMPLES = """
|
|||
type: session
|
||||
control: '[success=1 default=ignore]'
|
||||
module_path: pam_succeed_if.so
|
||||
module_arguments: 'crond quiet'
|
||||
module_arguments: crond,quiet
|
||||
state: args_present
|
||||
|
||||
- name: Ensure specific arguments are present in a rule (alternative)
|
||||
pamd:
|
||||
name: system-auth
|
||||
type: session
|
||||
control: '[success=1 default=ignore]'
|
||||
module_path: pam_succeed_if.so
|
||||
module_arguments:
|
||||
- crond
|
||||
- quiet
|
||||
state: args_present
|
||||
|
||||
- name: Module arguments requiring commas must be listed as a Yaml list
|
||||
pamd:
|
||||
name: special-module
|
||||
type: account
|
||||
control: required
|
||||
module_path: pam_access.so
|
||||
module_arguments:
|
||||
- listsep=,
|
||||
state: args_present
|
||||
|
||||
- name: Update specific argument value in a rule
|
||||
|
@ -219,6 +242,7 @@ dest:
|
|||
...
|
||||
'''
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
import os
|
||||
|
@ -259,18 +283,18 @@ class PamdRule(object):
|
|||
|
||||
if '[' in stringline:
|
||||
pattern = re.compile(
|
||||
r"""([\-A-Za-z0-9_]+)\s* # Rule Type
|
||||
\[([A-Za-z0-9_=\s]+)\]\s* # Rule Control
|
||||
([A-Za-z0-9_\.]+)\s* # Rule Path
|
||||
([A-Za-z0-9_=<>\-\s]*)""", # Rule Args
|
||||
r"""([\-A-Za-z0-9_]+)\s* # Rule Type
|
||||
\[([A-Za-z0-9_=\s]+)\]\s* # Rule Control
|
||||
([A-Za-z0-9_\-\.]+)\s* # Rule Path
|
||||
([A-Za-z0-9,_=<>\-\s]*)""", # Rule Args
|
||||
re.X)
|
||||
complicated = True
|
||||
else:
|
||||
pattern = re.compile(
|
||||
r"""([\-A-Za-z0-9_]+)\s* # Rule Type
|
||||
([A-Za-z0-9_]+)\s* # Rule Control
|
||||
([A-Za-z0-9_\.]+)\s* # Rule Path
|
||||
([A-Za-z0-9_=<>\-\s]*)""", # Rule Args
|
||||
([A-Za-z0-9_\-\.]+)\s* # Rule Path
|
||||
([A-Za-z0-9,_=<>\-\s]*)""", # Rule Args
|
||||
re.X)
|
||||
|
||||
result = pattern.match(stringline)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue