feat: implement custom 1Password lookup plugin and update references in Ansible tasks
Some checks failed
Nix Format Check / check-format (push) Failing after 38s

This commit is contained in:
Menno van Leeuwen 2025-03-11 21:50:40 +01:00
parent 0b29388f1a
commit 22bbda6b19
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE
6 changed files with 23 additions and 19 deletions

View File

@ -14,7 +14,7 @@ The lookup plugin accepts a 1Password reference string in the format `op://vault
```yaml ```yaml
- name: Fetch a secret from 1Password - name: Fetch a secret from 1Password
debug: debug:
msg: "{{ lookup('onepassword', 'op://vault/item/password') }}" msg: "{{ lookup('my_1password', 'op://vault/item/password') }}"
``` ```
## Examples ## Examples
@ -24,14 +24,14 @@ The lookup plugin accepts a 1Password reference string in the format `op://vault
```yaml ```yaml
- name: Fetch API key - name: Fetch API key
debug: debug:
msg: "{{ lookup('onepassword', 'op://My Vault/API Credentials/token') }}" msg: "{{ lookup('my_1password', 'op://My Vault/API Credentials/token') }}"
``` ```
### Using with templates ### Using with templates
```yaml ```yaml
# In your template file (e.g., config.j2) # In your template file (e.g., config.j2)
api_key: "{{ lookup('onepassword', 'op://My Vault/API Credentials/token') }}" api_key: "{{ lookup('my_1password', 'op://My Vault/API Credentials/token') }}"
``` ```
### Multiple secrets ### Multiple secrets
@ -40,8 +40,8 @@ api_key: "{{ lookup('onepassword', 'op://My Vault/API Credentials/token') }}"
- name: Fetch multiple secrets - name: Fetch multiple secrets
debug: debug:
msg: msg:
- "{{ lookup('onepassword', 'op://vault/item1/field') }}" - "{{ lookup('my_1password', 'op://vault/item1/field') }}"
- "{{ lookup('onepassword', 'op://vault/item2/field') }}" - "{{ lookup('my_1password', 'op://vault/item2/field') }}"
``` ```
## Error Handling ## Error Handling

View File

@ -2,7 +2,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
DOCUMENTATION = """ DOCUMENTATION = """
name: onepassword name: my_1password
author: Menno author: Menno
version_added: "1.0" version_added: "1.0"
short_description: fetch secrets from 1Password short_description: fetch secrets from 1Password
@ -17,15 +17,15 @@ DOCUMENTATION = """
EXAMPLES = """ EXAMPLES = """
- name: fetch password using 1Password reference - name: fetch password using 1Password reference
debug: debug:
msg: "{{ lookup('onepassword', 'op://vault/item/password') }}" msg: "{{ lookup('my_1password', 'op://vault/item/password') }}"
- name: fetch username from item - name: fetch username from item
debug: debug:
msg: "{{ lookup('onepassword', 'op://vault/item/username') }}" msg: "{{ lookup('my_1password', 'op://vault/item/username') }}"
- name: fetch custom field - name: fetch custom field
debug: debug:
msg: "{{ lookup('onepassword', 'op://vault/item/custom_field') }}" msg: "{{ lookup('my_1password', 'op://vault/item/custom_field') }}"
""" """
RETURN = """ RETURN = """

View File

@ -4,7 +4,7 @@ services:
image: ghcr.io/tailscale/golink:main image: ghcr.io/tailscale/golink:main
user: root user: root
environment: environment:
- TS_AUTHKEY={{ lookup('onepassword', 'op://j7nmhqlsjmp2r6umly5t75hzb4/GoLink/TS_AUTHKEY') }} - TS_AUTHKEY={{ lookup('my_1password', 'op://j7nmhqlsjmp2r6umly5t75hzb4/GoLink/TS_AUTHKEY') }}
volumes: volumes:
- {{ golink_data_dir }}:/home/nonroot - {{ golink_data_dir }}:/home/nonroot
restart: "unless-stopped" restart: "unless-stopped"

View File

@ -7,6 +7,6 @@ NEXTAUTH_URL=http://localhost:3000
DATA_DIR=/data DATA_DIR=/data
NEXTAUTH_SECRET="{{ lookup('onepassword', 'op://j7nmhqlsjmp2r6umly5t75hzb4/Hoarder/NEXTAUTH_SECRET') }}" NEXTAUTH_SECRET="{{ lookup('my_1password', 'op://j7nmhqlsjmp2r6umly5t75hzb4/Hoarder/NEXTAUTH_SECRET') }}"
MEILI_MASTER_KEY="{{ lookup('onepassword', 'op://j7nmhqlsjmp2r6umly5t75hzb4/Hoarder/MEILI_MASTER_KEY') }}" MEILI_MASTER_KEY="{{ lookup('my_1password', 'op://j7nmhqlsjmp2r6umly5t75hzb4/Hoarder/MEILI_MASTER_KEY') }}"
OPENAI_API_KEY="{{ lookup('onepassword', 'op://j7nmhqlsjmp2r6umly5t75hzb4/Hoarder/OPENAI_API_KEY') }}" OPENAI_API_KEY="{{ lookup('my_1password', 'op://j7nmhqlsjmp2r6umly5t75hzb4/Hoarder/OPENAI_API_KEY') }}"

View File

@ -1,12 +1,16 @@
--- ---
- name: Configure SSHFS - name: Configure SSHFS
block: block:
- name: SSHFS Details - name: Debug which plugin is being used
ansible.builtin.debug:
msg: "Using lookup plugins from: {{ lookup('pipe', 'ansible-config dump | grep DEFAULT_LOOKUP_PLUGIN_PATH') }}"
- name: Get SSHFS credentials via local lookup
delegate_to: localhost
ansible.builtin.set_fact: ansible.builtin.set_fact:
# Use lookup with explicit plugin path to ensure our custom plugin is used sshfs_user: "{{ lookup('my_1password', 'op://j7nmhqlsjmp2r6umly5t75hzb4/5j5y5axfjr3f3sn5nixb6htg4y/username') }}"
sshfs_user: "{{ lookup('file', lookup('onepassword', 'op://j7nmhqlsjmp2r6umly5t75hzb4/5j5y5axfjr3f3sn5nixb6htg4y/username')) }}" sshfs_pass: "{{ lookup('my_1password', 'op://j7nmhqlsjmp2r6umly5t75hzb4/5j5y5axfjr3f3sn5nixb6htg4y/new_password') }}"
sshfs_pass: "{{ lookup('file', lookup('onepassword', 'op://j7nmhqlsjmp2r6umly5t75hzb4/5j5y5axfjr3f3sn5nixb6htg4y/new_password')) }}" sshfs_host: "{{ lookup('my_1password', 'op://j7nmhqlsjmp2r6umly5t75hzb4/5j5y5axfjr3f3sn5nixb6htg4y/host') }}"
sshfs_host: "{{ lookup('file', lookup('onepassword', 'op://j7nmhqlsjmp2r6umly5t75hzb4/5j5y5axfjr3f3sn5nixb6htg4y/host')) }}"
sshfs_port: 23 sshfs_port: 23
remote_path: /mnt/storage-box remote_path: /mnt/storage-box

View File

@ -8,7 +8,7 @@
tasks: tasks:
- name: Test lookup with direct reference - name: Test lookup with direct reference
ansible.builtin.debug: ansible.builtin.debug:
msg: "{{ lookup('onepassword', 'op://j7nmhqlsjmp2r6umly5t75hzb4/5j5y5axfjr3f3sn5nixb6htg4y/host') }}" msg: "{{ lookup('my_1password', 'op://j7nmhqlsjmp2r6umly5t75hzb4/5j5y5axfjr3f3sn5nixb6htg4y/host') }}"
- name: Template with lookup - name: Template with lookup
ansible.builtin.template: ansible.builtin.template: