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

[DRAFT]: Add support for state:query to management modules #782

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

t-woerner
Copy link
Member

@t-woerner t-woerner commented Feb 25, 2022

Fixes #660
Fixes #482

@t-woerner t-woerner changed the title [DRAFT]: Add support for stete:fetched to user module [DRAFT]: Add support for state:fetched to user module Feb 25, 2022
@t-woerner t-woerner force-pushed the state_fetched branch 2 times, most recently from 85e9363 to 7497eeb Compare February 28, 2022 13:32
@varunmylaraiah
Copy link
Collaborator

@t-woerner Do you have a plan to add state: fetched for all users?
If so, is it possible to implement a range? like, fetch 0-100 users or 5000-5500 etc...In that case, it will not brack if we have many users.

@rjeffman
Copy link
Member

/azp run Master and Pull Requests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@t-woerner t-woerner force-pushed the state_fetched branch 2 times, most recently from 827c6ed to 1246318 Compare August 25, 2022 15:23
@t-woerner t-woerner changed the title [DRAFT]: Add support for state:fetched to user module [DRAFT]: Add support for state:query to user module Aug 25, 2022
@t-woerner t-woerner force-pushed the state_fetched branch 3 times, most recently from 102736d to 5f0e749 Compare August 26, 2022 13:08
@t-woerner t-woerner changed the title [DRAFT]: Add support for state:query to user module [DRAFT]: Add support for state:query to management module Aug 26, 2022
@t-woerner t-woerner changed the title [DRAFT]: Add support for state:query to management module [DRAFT]: Add support for state:query to management modules Aug 26, 2022
@t-woerner t-woerner force-pushed the state_fetched branch 2 times, most recently from 7985bac to 864c54c Compare August 29, 2022 16:15
@rjeffman rjeffman self-requested a review September 26, 2022 23:14
@t-woerner t-woerner force-pushed the state_fetched branch 2 times, most recently from 43a5f70 to 3a79a44 Compare September 28, 2023 13:13
This method enables to execute query state within IPAAnsibleModule.
The parameter query_param canbe used to select the returned parameters.

def execute_query(self, names, prefix, name_ipa_param,
                  query_param, query_command, query_param_settings):
    """
    Execute query state.

    Parameters
    ----------
    names: The main items to return
        It names is not None and not an empty list then all items
        found with "item_find" are returned, else the items in names.
    prefix: The prefix for use with several main items
        The prefix is "users" for the "user" module. It is used
        if only the list of main items (example: users) is returned.
    name_ipa_param: The IPA param name of the name parameter
        This is for example "uid" that is used for the user name in
        the user module.
    query_param: The parameters to return
        The parameters that should be returned. If query_param is
        ["ALL"], all parameters in ipa_pram_names will be returned.
    query_param_settings: IPA base parameters, all and mapping
        The dict provides all parameters the "ALL" list and the
        mapping of the default module paramter name to IPA option name
        if it is not the same.
        Example: "uid" for user name of the user commands.
    query_command: The Query function
        This is a module function that returns the structure(s) from
        the show or find command.

    """

Add to DOCUMENTATION:

  query_param:
    description: The fields to query with state=query
    required: false

  state:
    description: State to ensure
    default: present
    choices: ["present", "absent",
              "query"]

Add to the code:

    query_param_settings = {
        "ALL": [
            "dn", "objectclass", "ipauniqueid", "ipantsecurityidentifier",
            "name",
            ...
        ],
        "BASE": [
            "name",
            ...
            "disabled"
        ],
        "mapping": {
            "name": "uid",
            ...
            "disabled": "nsaccountock"
        }
    }

    def main():

        ...
        invalid = []
        if state == "present":
            ...
        else:
            ...

            if state == "query":
                if action == "member":
                    module.fail_json(
                        msg="Query is not possible with action=member")
            else:
                invalid.append("query_param")
        ...

        # Connect to IPA API
        with ansible_module.ipa_connect():

            if state == "query":
                exit_args = ansible_module.execute_query(
                    names, "users", "uid", query_param, user_find,
                    query_param_settings)

                ansible_module.exit_json(changed=False, user=exit_args)

             # remainaing module code follows here
The query_param parameter has been added, together with the dict
query_param_settings. Also a new convert_result and user_find function
has been added.
The query_param parameter has been added, together with the dict
query_param_settings. The existing find_group function has been
transformed into user_show to get the result for a single user and
new convert_result and user_find function have been added.
@arnoxit
Copy link

arnoxit commented May 28, 2024

This would be a very useful feature to add for hosts as well as users and groups.

@rjeffman
Copy link
Member

@arnoxit the plan is to add query support for all modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFE] need a fact/info module Get the value for current DNS record or check if DNS record exists
4 participants