### Install 1Password Connect Ansible Collection Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/README.md Install the Ansible collection from Ansible Galaxy. This is the first step to using the collection. ```bash ansible-galaxy collection install onepassword.connect ``` -------------------------------- ### Get Item Information with Ansible Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/README.md Example of retrieving information about a specific 1Password item, including its fields and metadata, using the `item_info` module. Ensure the `OP_CONNECT_HOST` environment variable is set and a valid JWT token is provided. ```yaml --- hosts: localhost vars: connect_token: "valid.jwt.here" environment: OP_CONNECT_HOST: http://localhost:8001 collections: - onepassword.connect tasks: - name: Find the item with the label "Staging Database" in the vault "Staging Env" item_info: token: "{{ connect_token }}" item: Staging Database vault: Staging Env no_log: true register: op_item ``` -------------------------------- ### Create a 1Password Secret using generic_item Module Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/USAGEGUIDE.md This example demonstrates how to create a new secret item in 1Password using the `generic_item` module. It shows how to define item fields, including concealed fields and auto-generated values with specific recipes. Ensure `no_log: true` is set to prevent sensitive data exposure in Ansible logs. ```yaml --- - name: Create 1Password Secret hosts: localhost vars: connect_token: "api.jwt.here" environment: OP_CONNECT_HOST: http://localhost:8001 tasks: - onepassword.connect.generic_item: token: "{{ connect_token }}" vault_id: "qwerty56789asdf" title: Club Membership state: present fields: - label: Codeword value: "hunter2" section: "Personal Info" field_type: concealed - label: Random Code generate_value: on_create generator_recipe: length: 16 include_letters: yes include_digits: yes include_symbols: no no_log: true register: op_item ``` -------------------------------- ### Install Ansible via virtualenv Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/CONTRIBUTE.md Installs a supported version of Ansible-core and the community package within a Python virtual environment. Ensure Python v3.10 or greater is installed. ```bash python3 -m venv /onepassword_ansible source /onepassword_ansible activate pip3 install 'ansible-core>=2.16,<2.17' 'ansible>=9,<10' ``` -------------------------------- ### Plugin Test Directory Structure Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/tests/README.md For plugin tests, include the plugin type in the directory name. For example, for a lookup plugin named '_foo_', use 'lookup_foo'. ```bash ./tests/integrations/targets/lookup_foo/ ``` ```bash ./tests/integration/targets/connection_bar/ ``` -------------------------------- ### Retrieve a Specific Field Value from a 1Password Item Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/USAGEGUIDE.md Use the `field_info` module to get the value of a specific field within a 1Password item. You can search by item name and field name, optionally specifying a vault and section. The field definition is registered to a variable. ```yaml --- hosts: localhost vars: connect_token: "valid.jwt.here" environment: OP_CONNECT_HOST: http://localhost:8001 collections: - onepassword.connect tasks: - name: Find a field labeled "username" in an item named "MySQL Database" in a specific vault. field_info: token: "{{ connect_token }}" item: MySQL Database field: username vault: 2zbeu4smcibizsuxmyvhdh57b6 no_log: true register: op_item - name: Print the field definition ansible.builtin.debug: msg: "{{ op_item.field }}" ``` -------------------------------- ### Run Unit Tests with Makefile Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/USAGEGUIDE.md Execute the unit tests for the 1Password Ansible collection using the provided Makefile target. Refer to the tests/README.md for more detailed testing information. ```shell make test ``` -------------------------------- ### Run Unit Tests Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/tests/README.md Execute unit tests for the Ansible collection using the provided make target. ```bash make test/unit ``` -------------------------------- ### Run Integration Tests Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/tests/README.md Execute integration tests for the Ansible collection using the provided make target. ```bash make test/integration ``` -------------------------------- ### Set Environment Variables for Testing Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/tests/README.md Before running tests, set these environment variables to configure the connection to the 1Password Connect server and specify the target vault. ```bash export OP_VAULT_ID=id_of_target_vault export OP_CONNECT_HOST=http_url_to_connect_server # see comment export OP_CONNECT_TOKEN=jwt_for_service_account ``` -------------------------------- ### Module Test Directory Structure Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/tests/README.md Place integration tests for a module in a directory named after the module within the targets directory. ```bash tests/integration/targets/foo/ ``` -------------------------------- ### `item_info` Module Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/USAGEGUIDE.md Retrieves information about a 1Password item, including its fields and metadata, by its title or UUID. ```APIDOC ## GET /api/items/{itemId} ### Description Retrieves information about a 1Password item, including its fields and metadata, by its title or UUID. ### Method GET ### Endpoint /api/items/{itemId} ### Parameters #### Path Parameters - **itemId** (string) - Required - The title or UUID of the item to retrieve. #### Query Parameters - **vault** (string) - Required - The ID or name of the vault to search within. #### Request Body None ### Request Example ```yaml --- hosts: localhost vars: connect_token: "valid.jwt.here" environment: OP_CONNECT_HOST: http://localhost:8001 collections: - onepassword.connect tasks: - name: Find the item with the label "Staging Database" in the vault "Staging Env" item_info: token: "{{ connect_token }}" item: Staging Database vault: Staging Env no_log: true register: op_item ``` ### Response #### Success Response (200) - **changed** (boolean) - Indicates if the item was changed (usually false for info retrieval). - **failed** (boolean) - Indicates if the operation failed. - **op_item** (object) - Contains the retrieved item details. - **category** (string) - The category of the item. - **createdAt** (string) - The creation timestamp. - **fields** (object) - An object containing the item's fields. - **id** (string) - The unique identifier of the item. - **tags** (array) - A list of tags associated with the item. - **title** (string) - The title of the item. - **updatedAt** (string) - The last updated timestamp. - **vault** (object) - Information about the vault the item belongs to. #### Response Example ```json { "changed": false, "failed": false, "op_item": { "category": "SERVER", "createdAt": "2020-11-23T15:29:07.312397-08:00", "fields": { "Test": { "id": "j6ao3EXAMPLEvmzbrtre", "label": "Test", "type": "STRING", "value": " எண்ண " }, "notesPlain": { "id": "notesPlain", "label": "notesPlain", "purpose": "NOTES", "type": "STRING" } }, "id": "bactwEXAMPLEpxhpjxymh7yy", "tags": [], "title": "Test Item 2", "updatedAt": "2020-11-23T15:29:07.312397-08:00", "vault": { "id": "4ktuuifg2ad7m4vEXAMPLEm" } } } ``` ### Error Handling (Specific error responses are not detailed in the provided text.) ``` -------------------------------- ### Find a 1Password Item by Name Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/USAGEGUIDE.md Use the `item_info` module to retrieve details about a 1Password item. Specify the item name and vault name to locate it. The output is registered to a variable for further use. ```yaml --- hosts: localhost vars: connect_token: "valid.jwt.here" environment: OP_CONNECT_HOST: http://localhost:8001 collections: - onepassword.connect tasks: - name: Find the item with the label "Staging Database" in the vault "Staging Env" item_info: token: "{{ connect_token }}" item: Staging Database vault: Staging Env no_log: true register: op_item ``` -------------------------------- ### Clone and Configure Ansible Collection Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/CONTRIBUTE.md Clones the Ansible collection repository into the correct directory structure for Ansible to recognize it and sets the ANSIBLE_COLLECTIONS_PATHS environment variable. This ensures Ansible can find custom collections. ```bash # Create the special ansible_collections folder and the onepassword namespace directory mkdir -p ~/onepassword/ansible_collections/onepassword cd ~/onepassword/ansible_collections/onepassword # Clone the collection repo into the namespace: {..}/ansible_collections/onepassword git clone git@github.com:1Password/ansible-onepasswordconnect-collection.git connect cd connect # Extend Ansible's collection lookup path # to first look for collections inside ~/onepassword/ansible_collections/... export ANSIBLE_COLLECTIONS_PATHS=~/onepassword:$ANSIBLE_COLLECTIONS_PATHS # Verify - you should see docs for the `generic_item` module in your terminal # activate your virtualenv before running the following ansible-doc onepassword.connect.generic_item ``` -------------------------------- ### `field_info` Module Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/USAGEGUIDE.md Retrieves the value of a specific field within a 1Password item. ```APIDOC ## GET /api/items/{itemId}/fields/{fieldId} ### Description Retrieves the value of a specific field within a 1Password item. The item is found by its title or UUID, and the field is found by its label. A section can be specified to narrow the search. ### Method GET ### Endpoint /api/items/{itemId}/fields/{fieldId} ### Parameters #### Path Parameters - **itemId** (string) - Required - The title or UUID of the item. - **fieldId** (string) - Required - The label or ID of the field. #### Query Parameters - **vault** (string) - Required - The ID or name of the vault containing the item. - **section** (string) - Optional - The name of the section the field belongs to. If not provided, the field name must be unique within the item. #### Request Body None ### Request Example ```yaml --- hosts: localhost vars: connect_token: "valid.jwt.here" environment: OP_CONNECT_HOST: http://localhost:8001 collections: - onepassword.connect tasks: - name: Find a field labeled "username" in an item named "MySQL Database" in a specific vault. field_info: token: "{{ connect_token }}" item: MySQL Database field: username vault: 2zbeu4smcibizsuxmyvhdh57b6 no_log: true register: op_item - name: Print the field definition ansible.builtin.debug: msg: "{{ op_item.field }}" ``` ### Response #### Success Response (200) - **value** (string) - The value of the field. - **section** (string) - The section the field belongs to. - **id** (string) - The unique identifier of the field. #### Response Example ```json { "value": "mysql_username_example", "section": "", "id": "fb3b40ac85f5435d26e" } ``` ### Error Handling (Specific error responses are not detailed in the provided text.) ``` -------------------------------- ### Debugging Ansible Modules Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/tests/README.md If standard debugging methods fail, you can insert a raise Exception statement within a module to halt execution and print a specific value. ```python raise Exception(some_value) ``` -------------------------------- ### Update an Item Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/USAGEGUIDE.md This task updates an existing 1Password item or creates it if it doesn't exist. It supports generating field values with different strategies. ```APIDOC ## POST /api/items ### Description Updates an existing 1Password item or creates it if it doesn't exist. Supports generating field values with different strategies. ### Method POST ### Endpoint /api/items ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **title** (string) - Required - The title of the item. - **uuid** (string) - Optional - The UUID of the item to update. - **state** (string) - Required - Should be 'present' to ensure the item exists. - **fields** (list) - Required - A list of field definitions for the item. - **label** (string) - Required - The label of the field. - **field_type** (string) - Required - The type of the field (e.g., 'concealed', 'string'). - **generate_value** (string) - Optional - Strategy for generating field values ('never', 'on_create', 'always'). - **generator_recipe** (object) - Optional - Configuration for value generation. - **length** (integer) - Required if `generate_value` is used - The desired length of the generated value. - **include_symbols** (boolean) - Optional - Whether to include symbols in the generated value. ### Request Example ```yaml - name: Update a 1Password Secret hosts: localhost vars: connect_token: "valid.jwt.here" environment: OP_CONNECT_HOST: http://localhost:8001 OP_VAULT_ID: "zyzzyz1234example" tasks: - onepassword.connect.generic_item: token: "{{ connect_token }}" title: Club Membership # uuid: 1ff75fa9fexample -- or use an Item ID to locate an item instead state: present fields: - label: Codeword field_type: concealed - label: Dashboard Password generate_value: always # new value is generated every time playbook is run generator_recipe: length: 16 include_symbols: no no_log: true ``` ### Response #### Success Response (200) - **changed** (boolean) - Indicates if the item was changed. - **failed** (boolean) - Indicates if the operation failed. #### Response Example (No specific success response body is detailed in the provided text, but it would typically reflect the state of the operation.) ### Error Handling (Specific error responses are not detailed in the provided text.) ``` -------------------------------- ### Update a 1Password Secret with Generated Value Source: https://github.com/1password/ansible-onepasswordconnect-collection/blob/main/USAGEGUIDE.md Use this task to update an existing 1Password item. The `generate_value: always` setting ensures a new value is created on each playbook run. Requires a generator recipe to be defined. ```yaml --- - name: Update a 1Password Secret hosts: localhost vars: connect_token: "valid.jwt.here" environment: OP_CONNECT_HOST: http://localhost:8001 OP_VAULT_ID: "zyzzyz1234example" tasks: - onepassword.connect.generic_item: token: "{{ connect_token }}" title: Club Membership # uuid: 1ff75fa9fexample -- or use an Item ID to locate an item instead state: present fields: - label: Codeword field_type: concealed - label: Dashboard Password generate_value: always # new value is generated every time playbook is run generator_recipe: length: 16 include_symbols: no no_log: true ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.