Searching for Item by name / field in Ansible Connect
I've just started using connect, and it's a terrific feature, it will solve loads of problems.
I'm just wondering if the ansible plugin has a way to search? Or if you can get things solely by name?
If so then perhaps I would be better using the CLI Plugin?
1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Connect 2.0.0 Docker
Sync Type: Connect
Referrer: forum-search:ansible
Comments
-
Hello!
Yes, the Ansible collection does have a search plugin: https://github.com/1Password/ansible-onepasswordconnect-collection#item_info-module . If you have a specific use case in mind, I can also recommend a few approaches.
You can use it to get information about a specific item using just the item's name. You can also search for a field within an item if you want just a specific value.
For example:
--- hosts: localhost environment: OP_CONNECT_HOST: http://localhost:8080 OP_CONNECT_TOKEN: "valid.jwt.here" collections: - onepassword.connect tasks: - name: Find the item with the label "Staging Database" in the vault "Staging Env" item_info: item: Staging Database vault: Staging Env # You can limit the search to a specific vault, too! no_log: true register: op_item
This playbook will:
- contact the 1Password Connect server in your infrastructure
- make a GET request to find the item with the name "Staging Database"
- register the result to
op_item
if the item can be found
You can then access the returned item data in the rest of your play book. You could get the item's ID by accessing
op_item.id
or reference a field by name viaop_item.fields.yourFieldNameHere
0 -
HI David,
Thanks, but what about if I was to search by a different field other than Name?
For example if I was to add a field called hostname, or IP, and then wanted to search where the IP was 192.168.X.X
Kind Regards
Mike
0 -
Hey Mike,
Right now we only support searching by field name. I can suggest you open an issue on the GitHub repo and we can gather some interest on searching for field(s) by value with the Ansible module.
We can definitely consider adding support to filter items by their tags, too. Would that be a viable alternative?
0 -
Will do, thanks David
0 -
On behalf of David, you are very welcome :)
0