Commit Graph

393 Commits

Author SHA1 Message Date
Rafael Guterres Jeffman
1054bdd0e3 Fix ansible-lint E206 (var-spacing) on all test and example playbooks. 2021-09-29 15:49:00 -03:00
Rafael Guterres Jeffman
7e0624d836 ipavault: Allow execution of plugin in client host.
Update vault README file and add tests for executing plugin with
`ipaapi_context` set to `client`.

A new test playbook can be found at:

    tests/vault/test_vault_client_context.yml

As `ipavault` only works in client context, an error is raised if it
is explicitly executed in a server context.
2021-09-28 19:16:11 -03:00
Rafael Guterres Jeffman
a599f4ad87 ipapermission: Allow execution of plugin in client host.
Update permission README file and add tests for executing plugin with
`ipaapi_context` set to `client`.

A new test playbook can be found at:

    tests/permission/test_permission_client_context.yml

The new test file can be executed in a FreeIPA client host that is
not a server. In this case, it should be defined in the `ipaclients`
group, in the inventory file.

Due to differences in data returned when running in a client context,
some values had to be modified so that comparision works and an
unnecessary call to IPA API is executed.
2021-09-28 10:19:43 -03:00
Rafael Guterres Jeffman
cf7b197a1f ipadnszone: Allow execution of plugin in client host.
Update dnszone README file and add tests for executing plugin with
`ipaapi_context` set to `client`.

A new test playbook can be found at:

    tests/dnszone/test_dnszone_client_context.yml

The new test file can be executed in a FreeIPA client host that is
not a server. In this case, it should be defined in the `ipaclients`
group, in the inventory file.

Due to differences in data returned when running in a client context,
verification if zone is active had to be modified.
2021-09-28 10:19:43 -03:00
Rafael Guterres Jeffman
da45d74f75 ipadnsforwardzone: Allow execution of plugin in client host.
Update dnsforwardzone README file and add tests for executing plugin with
`ipaapi_context` set to `client`.

A new test playbook can be found at:

    tests/dnsforwardzone/test_dnsforwardzone_client_context.yml

The new test file can be executed in a FreeIPA client host that is
not a server. In this case, it should be defined in the `ipaclients`
group, in the inventory file.

Due to differences in data returned when running ipadnsforwardzone in
a client context, some values had to be modified so that comparision
works, avoiding unnecessary IPA API calls.
2021-09-28 10:19:43 -03:00
Rafael Guterres Jeffman
8bc6b01f49 modules: Allow execution of plugins in an IPA client host.
Add a new configuration variable, `ipaapi_context` to IPAAnsibleModule
base specs, accepting only 'server' or 'client' values.

By using this variable, an user can select the environment context in
which the module will execute, server or client. This change will allow
configuration of the server without requiring login access (e.g. `ssh`)
to the server.

The default behavior is to use a `server` context, but this behavior
can be modified by the plugin, if it sets the `context` parameter when
connecting to IPA API.
2021-09-27 13:51:53 -03:00
Rafael Guterres Jeffman
97670e8e46 Merge pull request #640 from t-woerner/group_class_fixes
group: Fix nonposix, posix and external handling and conversions
2021-09-16 16:55:25 -03:00
Thomas Woerner
1f25024396 group: Fix nonposix, posix and external handling and conversions
The nonposix, posix and external parameters need to be mutually
exclusive. external was missing in this list. Only one of the three
parameters can be used.

external can not be set to no/false. This results in an error now.

if nonposix is used, posix is set as not nonposix. The nonposix
parameter is not used within the code anymore..

New tests have been added to tests the addition of users with for
nonposix and posix groups. The tests for the external group is not
active due to the need of an AD.

Fixes: #528 (Error creating nonposix group)
2021-09-16 13:30:34 +02:00
Thomas Woerner
ccb07cbef5 Merge pull request #634 from rjeffman/sudocmd_use_execute_ipa_commands
Use execute_ipa_commands for sudocmd plugins.
2021-09-16 11:14:29 +02:00
Thomas Woerner
3d6bf87187 Merge pull request #637 from rjeffman/ipaconfig_missing_params
config: Fix data returned from module.
2021-09-16 10:20:53 +02:00
Rafael Guterres Jeffman
87de471d97 config: Fix data returned from module.
When retrieving IPA configuration using ipaconfig module, a few
variables were not returning, and some data had the wrong data format.

This patch fix both issues and apply some refactoring, as data was
being retrieved from IPA API in different places using different
methods.
2021-09-15 08:53:39 -03:00
Rafael Guterres Jeffman
1615f59f12 sudocmdgroup: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-14 14:10:25 -03:00
Rafael Guterres Jeffman
8723aafd4f sudocmdgroup: Reduce addition and deletion of members to changed only
Use gen_add_list and gen_intersection_list for sudocmd member handling,
to reduce the add lists to only the new and del lists only to existing
entries.

This enables to remove the ignores for "already a member" and
"not a member" errors.
2021-09-14 14:10:25 -03:00
Rafael Guterres Jeffman
5175c870f2 config: Remove unused code.
Removed the definition of unused function 'gen_args()' from ipaconfig.
2021-09-14 10:04:36 -03:00
Rafael Guterres Jeffman
ae2f452c60 sudocmd: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-13 14:13:58 -03:00
Thomas Woerner
8dec9f774b Merge pull request #633 from rjeffman/topology_fix_usage_ipaansiblemodule
Fix documentation and usage of IPAAnsibleModule
2021-09-09 09:54:50 +02:00
Rafael Guterres Jeffman
602446004a ipatopologysuffix: Fix usage of IPAAnsibleModule.
Fix parameters used to IPAAnsibleModule.ipa_command, as a singlo list
was being used instead of a parameter list.
2021-09-09 00:19:59 -03:00
Rafael Guterres Jeffman
4c4668b437 IPAAnsibleModule: Fix example in documentation.
In the provided example for the class documentation, the parameters
passed to the `ipa_command` method were wrong, as a single list was
used instead of a parameter list.
2021-09-09 00:17:48 -03:00
Rafael Guterres Jeffman
b81f719b16 Merge pull request #630 from t-woerner/use_execute_ipa_commands
Use execute ipa commands
2021-09-08 18:20:29 -03:00
Thomas Woerner
15d7cbbf2b dnsrecord: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:34:07 +02:00
Thomas Woerner
a4aee3b2a6 host: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:34:07 +02:00
Thomas Woerner
3d13e7b6c0 user: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:34:07 +02:00
Thomas Woerner
b5bfcc13f9 sudorule: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:34:07 +02:00
Thomas Woerner
dc1027c3ca service: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:34:00 +02:00
Thomas Woerner
06e5382320 server: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:33:30 +02:00
Thomas Woerner
fba1cc1440 selfservice: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:33:30 +02:00
Thomas Woerner
01ef557ba6 role: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:33:30 +02:00
Thomas Woerner
a11c442902 pwpolicy: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:33:30 +02:00
Thomas Woerner
6c60b738a5 privilege: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:33:19 +02:00
Thomas Woerner
ffdae9cee8 permission: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:32:47 +02:00
Thomas Woerner
4392e32f6e location: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:32:20 +02:00
Thomas Woerner
ac8f3b047c hostgroup: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:32:20 +02:00
Thomas Woerner
6ae68980e8 hbacsvc: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:32:20 +02:00
Thomas Woerner
2c96d91d4c hbacsvcgroup: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-08 14:32:15 +02:00
Thomas Woerner
928deb2176 hbacrule: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-07 16:06:02 +02:00
Thomas Woerner
1907373023 group: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-07 15:55:01 +02:00
Thomas Woerner
95ffd2c5a6 delegation: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-07 15:55:01 +02:00
Thomas Woerner
e6f0eb2395 automember: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-07 15:55:01 +02:00
Thomas Woerner
917b3b62c7 IPAAnsibleModule: New staticethod member_error_handler
The staticmethod member_error_handler is handing the default member
related failures that can occur for modules with member support.
This can simply be enabled with fail_on_member_errors=True for
execute_ipa_commands.

An exception handler is also now usable with execute_ipa_commands. In
addition to the the exception it is also getting the same user defined
arguments that the result_handler is getting.

handle_result has been renamed in result_handler and handle_result_user_args
has been renamed to handlers_user_args.

Additionally the errors list does not need to be defined in the module.
The method execute_ipa_commands is doing this internally and is also
adding error: error to handlers_user_args if the handler is having errors
in the argspec and errors is not yet set in handlers_user_args.

Tests have been added to make sure that no user args for the handler
have been set without an own result or exception handler. Also the use of
fail_on_member_errors together with a result_andler is leading to an
error.
2021-09-07 15:49:14 +02:00
Rafael Guterres Jeffman
6dbbe3a2fe Merge pull request #632 from zpericic/ipadnszone_allow_query
ipadnszone: Accept localhost and localnet in allow_query.
2021-09-06 10:51:50 -03:00
Zoran Peričić
2990abb33b ipadnszone: Accept localhost and localnet in allow_query. 2021-09-05 18:36:37 +02:00
Thomas Woerner
29fb281bcb Merge pull request #582 from rjeffman/dnszone_add_check_mode_support
ipadnszone: add check mode support
2021-09-03 13:12:05 +02:00
Thomas Woerner
07b47cab2d Merge pull request #623 from rjeffman/dnszone_deprecate_soa_serial
dnszone: remove variable `serial`.
2021-09-03 13:10:31 +02:00
Rafael Guterres Jeffman
8b1a4fee08 Merge pull request #626 from t-woerner/new_IPAAnsibleModule
New IPAAnsibleModule class
2021-09-02 18:19:53 -03:00
Thomas Woerner
ed3dd3ea71 config: Use IPAAnsibleModule class
ipaadmin_variables are handled by IPAAnsibleModule,
ansible_module.params_get is used to get the parameters and
ansible_module.ipa_connect is used to simplify the module.
2021-09-02 17:07:48 +02:00
Thomas Woerner
3e98ed5442 ansible_freeipa_module: Cleanup of unused functions and attributes
Moved ipamodule_base_spec into IPAAnsibleModule.
This simplifies to add addtitional base vars to derived classes without
the need to dusplicae the code to extend argument_spec.

Removed execute_api_command.
This is not used anymore.

Removed get_ipamodule_base_vars.
This is not used anymore.

Removed self.ipaadmin_* and self.ccache_* from IPAAnsibleModule.__init__
These are not used and therefore can be removed.
2021-09-02 17:07:48 +02:00
Thomas Woerner
55341a0310 ansible_freeipa_module: New execute_ipa_commands in IPAAnsibleModule
execute_ipa_commands executes IPA API commands from the given command
list. With the handle_result and handle_result_user_args it is possible
to have a handling of the result return by the ipa commands for example
to return passwords.

Parameters

    commands: list of string tuple
        The list of commands in the form (name, command and args)
        For commands that do not require a 'name', None needs be
        used.
    handle_result: function
        The user function to handle results of the single commands
    handle_result_user_args: dict (user args mapping)
        The user args to pass to handle_result function

Example (ipauser module)

    def handle_result(result, command, name, args, exit_args):
        if "random" in args and command in ["user_add", "user_mod"] \
           and "randompassword" in result["result"]:
            exit_args.setdefault(name, {})["randompassword"] = \
                result["result"]["randompassword"]

    exit_args = {}
    changed = module.execute_ipa_commands(commands, handle_result,
                                          exit_args=exit_args)

    if len(names) == 1:
        ansible_module.exit_json(changed=changed,
                                 user=exit_args[names[0]])
    else:
        ansible_module.exit_json(changed=changed, user=exit_args)
2021-09-02 17:07:40 +02:00
Rafael Guterres Jeffman
706e1f5be3 automountlocation: Use IPAAnsibleModule class
Use IPAAnsibleModule methods and ipamodule_base_docs ducument fragment.
2021-09-02 16:32:02 +02:00
Rafael Guterres Jeffman
21a48d5968 dnszone: Use IPAAnsibleModule class.
Use IPAAnsibleModule methods and ipamodule_base_docs ducument fragment.
2021-09-02 16:32:02 +02:00
Rafael Guterres Jeffman
0c430d0aa9 Make IPAAnsibleModule base class of FreeIPABaseModule.
By making IPAAnsibleModule the base class of FreeIPABaseModule, instead
of AnsibleModule, some methods on FreeIPABaseModule can be removed and
suport for commom parameters in modules using the older class can use
the same commom parameters (ipaadmin_principal and ipaadmin_password)
as the other parameters. This will also allow easier deprecation of
FreeIPABaseModule, which is hard to maintain.

To be able to use IPAAnsibleModule as the base class, it was moved
within the file, to position before FreeIPABaseModule declaration.

This patch also modifies IPAAnsibleModule by:

    * removing usage of `self` in methods not requiring it, turning
      the methods into @statimethod;

    * adding comments to all the methods in IPAAnsibleModule, which
      makes it easier to understand what the individual methods do,
      and what their parameters represent.
2021-09-02 16:32:02 +02:00