Skip to content
Snippets Groups Projects
Unverified Commit 72d54d2f authored by Rafael Guterres Jeffman's avatar Rafael Guterres Jeffman Committed by GitHub
Browse files

Merge pull request #624 from t-woerner/ipamodule_base_vars

New ipamodule_base_vars
parents f1a8618b 7a665bdb
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ jobs: ...@@ -15,7 +15,7 @@ jobs:
- name: Run ansible-doc-test - name: Run ansible-doc-test
run: | run: |
python -m pip install "ansible < 2.10" python -m pip install "ansible < 2.10"
ANSIBLE_LIBRARY="." python utils/ansible-doc-test -v roles plugins ANSIBLE_LIBRARY="." ANSIBLE_DOC_FRAGMENT_PLUGINS="." python utils/ansible-doc-test -v roles plugins
check_docs_latest: check_docs_latest:
name: Check Ansible Documentation with latest Ansible. name: Check Ansible Documentation with latest Ansible.
...@@ -28,5 +28,5 @@ jobs: ...@@ -28,5 +28,5 @@ jobs:
- name: Run ansible-doc-test - name: Run ansible-doc-test
run: | run: |
python -m pip install ansible python -m pip install ansible
ANSIBLE_LIBRARY="." python utils/ansible-doc-test -v roles plugins ANSIBLE_LIBRARY="." ANSIBLE_DOC_FRAGMENT_PLUGINS="." python utils/ansible-doc-test -v roles plugins
...@@ -24,6 +24,7 @@ jobs: ...@@ -24,6 +24,7 @@ jobs:
env: env:
ANSIBLE_MODULE_UTILS: plugins/module_utils ANSIBLE_MODULE_UTILS: plugins/module_utils
ANSIBLE_LIBRARY: plugins/modules ANSIBLE_LIBRARY: plugins/modules
ANSIBLE_DOC_FRAGMENT_PLUGINS: plugins/doc_fragments
yamllint: yamllint:
name: Verify yamllint name: Verify yamllint
......
...@@ -7,7 +7,7 @@ repos: ...@@ -7,7 +7,7 @@ repos:
always_run: false always_run: false
pass_filenames: true pass_filenames: true
files: \.(yaml|yml)$ files: \.(yaml|yml)$
entry: env ANSIBLE_LIBRARY=./plugins/modules ANSIBLE_MODULE_UTILS=./plugins/module_utils ansible-lint --force-color entry: env ANSIBLE_LIBRARY=./plugins/modules ANSIBLE_MODULE_UTILS=./plugins/module_utils ANSIBLE_DOC_FRAGMENT_PLUGINS=./plugins/doc_fragments ansible-lint --force-color
- repo: https://github.com/adrienverge/yamllint.git - repo: https://github.com/adrienverge/yamllint.git
rev: v1.26.1 rev: v1.26.1
hooks: hooks:
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Authors:
# Thomas Woerner <twoerner@redhat.com>
#
# Copyright (C) 2021 Red Hat
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class ModuleDocFragment(object): # pylint: disable=R0205,R0903
DOCUMENTATION = r"""
options:
ipaadmin_principal:
description: The admin principal.
default: admin
ipaadmin_password:
description: The admin password.
required: false
"""
...@@ -109,6 +109,22 @@ else: ...@@ -109,6 +109,22 @@ else:
if six.PY3: if six.PY3:
unicode = str unicode = str
# AnsibleModule argument specs for all modules
ipamodule_base_spec = dict(
ipaadmin_principal=dict(type="str", default="admin"),
ipaadmin_password=dict(type="str", required=False, no_log=True),
)
# Get ipamodule common vars as nonlocal
def get_ipamodule_base_vars(module):
ipaadmin_principal = module_params_get(module, "ipaadmin_principal")
ipaadmin_password = module_params_get(module, "ipaadmin_password")
return dict(
ipaadmin_principal=ipaadmin_principal,
ipaadmin_password=ipaadmin_password,
)
def valid_creds(module, principal): # noqa def valid_creds(module, principal): # noqa
"""Get valid credentials matching the princial, try GSSAPI first.""" """Get valid credentials matching the princial, try GSSAPI first."""
if "KRB5CCNAME" in os.environ: if "KRB5CCNAME" in os.environ:
......
...@@ -31,13 +31,9 @@ DOCUMENTATION = """ ...@@ -31,13 +31,9 @@ DOCUMENTATION = """
module: ipalocation module: ipalocation
short description: Manage FreeIPA location short description: Manage FreeIPA location
description: Manage FreeIPA location description: Manage FreeIPA location
extends_documentation_fragment:
- ipamodule_base_docs
options: options:
ipaadmin_principal:
description: The admin principal.
default: admin
ipaadmin_password:
description: The admin password.
required: false
name: name:
description: The list of location name strings. description: The list of location name strings.
required: true required: true
...@@ -73,7 +69,8 @@ RETURN = """ ...@@ -73,7 +69,8 @@ RETURN = """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ansible_freeipa_module import \ from ansible.module_utils.ansible_freeipa_module import \
temp_kinit, temp_kdestroy, valid_creds, api_connect, api_command, \ temp_kinit, temp_kdestroy, valid_creds, api_connect, api_command, \
compare_args_ipa, module_params_get compare_args_ipa, module_params_get, ipamodule_base_spec, \
get_ipamodule_base_vars
import six import six
if six.PY3: if six.PY3:
...@@ -99,12 +96,8 @@ def gen_args(description): ...@@ -99,12 +96,8 @@ def gen_args(description):
def main(): def main():
ansible_module = AnsibleModule( # Arguments
argument_spec = dict( argument_spec = dict(
# general
ipaadmin_principal=dict(type="str", default="admin"),
ipaadmin_password=dict(type="str", required=False, no_log=True),
name=dict(type="list", aliases=["idnsname"], name=dict(type="list", aliases=["idnsname"],
default=None, required=True), default=None, required=True),
# present # present
...@@ -112,7 +105,11 @@ def main(): ...@@ -112,7 +105,11 @@ def main():
# state # state
state=dict(type="str", default="present", state=dict(type="str", default="present",
choices=["present", "absent"]), choices=["present", "absent"]),
), )
argument_spec.update(ipamodule_base_spec)
ansible_module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True, supports_check_mode=True,
) )
...@@ -121,9 +118,7 @@ def main(): ...@@ -121,9 +118,7 @@ def main():
# Get parameters # Get parameters
# general # general
ipaadmin_principal = module_params_get(ansible_module, base_vars = get_ipamodule_base_vars(ansible_module)
"ipaadmin_principal")
ipaadmin_password = module_params_get(ansible_module, "ipaadmin_password")
names = module_params_get(ansible_module, "name") names = module_params_get(ansible_module, "name")
# present # present
...@@ -156,9 +151,10 @@ def main(): ...@@ -156,9 +151,10 @@ def main():
ccache_dir = None ccache_dir = None
ccache_name = None ccache_name = None
try: try:
if not valid_creds(ansible_module, ipaadmin_principal): if not valid_creds(ansible_module, base_vars["ipaadmin_principal"]):
ccache_dir, ccache_name = temp_kinit(ipaadmin_principal, ccache_dir, ccache_name = temp_kinit(
ipaadmin_password) base_vars["ipaadmin_principal"],
base_vars["ipaadmin_password"])
api_connect() api_connect()
commands = [] commands = []
......
...@@ -30,9 +30,11 @@ import subprocess ...@@ -30,9 +30,11 @@ import subprocess
def run_ansible_doc(role, module, verbose=False): def run_ansible_doc(role, module, verbose=False):
playbook_dir, module_path = get_playbook_dir(role, module) playbook_dir, module_path = get_playbook_dir(role, module)
module_dir = os.path.dirname(module_path) module_dir = os.path.dirname(module_path)
doc_fragments = os.path.dirname(module_path)+"/../doc_fragments/"
command = ["env", command = ["env",
"ANSIBLE_LIBRARY=%s" % module_dir, "ANSIBLE_LIBRARY=%s" % module_dir,
"ANSIBLE_DOC_FRAGMENT_PLUGINS=%s" % doc_fragments,
"ansible-doc", "ansible-doc",
"--playbook-dir=%s" % playbook_dir, "--playbook-dir=%s" % playbook_dir,
"--type=module", "--type=module",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment