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

Standard method of passing extra arguments to lookup plugins #15

Closed
abadger opened this issue May 12, 2016 · 8 comments
Closed

Standard method of passing extra arguments to lookup plugins #15

abadger opened this issue May 12, 2016 · 8 comments

Comments

@abadger
Copy link
Contributor

abadger commented May 12, 2016

Proposal: Standard Method of Passing Extra Arguments to Lookup Plugins

Author: Toshio Kuratomi @abadger

Date: 2016/05/12

  • Status: WIP
  • Proposal type: Plugin API
  • Targeted Release: <future release #, ex. 2.2>
  • Associated PR: <link to GH PR in ansible/proposals if PR was submitted>
  • Estimated time to implement: 3 days

Motivation

Describe the reasons for this proposal.

Problems

A couple bugs lead me to find that lookup modules have a variety of ways of specifying their parameters:

Solution proposal

We need to add standard ways to specify and parse parameters to lookup plugins. We'd officially support something like the following (examples only. Exact syntax subject to change as it's thought through):

vars:
  pass: "{{ lookup( 'password', [{ term: "/dir with spaces/", length: 25, } ]) }}"
tasks:
  - debug:
    msg: "{{ item }}"
    with_password:
    - term: "/dir with spaces/"
      length: 25
  - debug:
    msg: "{{ item }}"
    with_password:
      - "/dir with spaces"

We would deprecate the former methods of specifying parameters:

- pass: "{{ lookup('password', '/dir_without_spaces length=25') }}"

I don't know if we'd continue to support the current style of arg passing that has support from the code when used via lookup() but not when used via with_* and that some plugins (for instance, password), are currently ignoring.

- pass: "{{ lookup('password', ["/dir with spaces"], length=25) }}"
# No when_password: style equivalent of the above.

Dependencies (optional)

Explain any dependencies. This section is optional but could be helpful.

Testing (optional)

Does / should this require testing, and if so, how? Describe here. This section is optional but could be helpful.

Documentation (optional)

Does / should this require documentation? If so, describe here. This section is optional but could be helpful.

Anything else?

If you'd like to add anything else beyond the above required and optional sections, you are welcome to do so.

@abadger abadger changed the title [WIP] Standard method of passing extra vars to lookup plugins [WIP] Standard method of passing extra arguments to lookup plugins May 20, 2016
@freeseacher
Copy link

any news on that ?
i am trying to understand how to pass host variable to consul_kv module. and have no idea :(

@abadger
Copy link
Contributor Author

abadger commented Jan 19, 2017

We need ideas of what this looks like and then ideas of how to implement the best of those ideas. This really just identifies the problem.

@bcoca
Copy link
Member

bcoca commented Jan 19, 2017

+1 to "arguments are always a dictionary" and deprecate old 'stringified' methods.

@abadger
Copy link
Contributor Author

abadger commented Feb 20, 2018

Closing this as it's now resolved. We advise using loop: and explicitly using query() or lookup() to pass arguments into lookup plugins. Arguments passed this way should always be coded as key word arguments (positional arguments to lookup plugins end up as the list of terms).

@abadger abadger closed this as completed Feb 20, 2018
@rgm3
Copy link

rgm3 commented Apr 11, 2018

@abadger Could you please provide an example of your advice or submit one to the lookup plugin documentation?

@abadger
Copy link
Contributor Author

abadger commented Apr 11, 2018

Hey, we don't normally see additional comments on closed bugs but luckily I saw your message on IRC. Here's an example of how to code the plugin: https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/lookup/aws_ssm.py#L142
And that plugin's documentation has an example of using it with loop: and query: https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/lookup/aws_ssm.py#L96

Documentation in the lookup plugin docs would be good if someone wants to work on that....

@fkuep
Copy link

fkuep commented Mar 31, 2021

@abadger Thank You!
Also ther is now a comment on LookupBase:
https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/lookup/__init__.py#L78-L105

Your aws_ssm example has moved
The I have working links from an old commit-hash

@bcoca
Copy link
Member

bcoca commented Apr 29, 2021

This is now 'implemented' via the plugin config system, all lookups should now shift to set_options call in their run method (see core lookups for examples)

@bcoca bcoca changed the title [WIP] Standard method of passing extra arguments to lookup plugins Standard method of passing extra arguments to lookup plugins Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants