2020-03-09 10:11:07 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2022-08-05 12:28:29 +02:00
|
|
|
# Copyright (c) 2018, Scott Buchanan <sbuchanan@ri.pn>
|
|
|
|
# Copyright (c) 2016, Andrew Zenk <azenk@umn.edu> (lastpass.py used as starting point)
|
|
|
|
# Copyright (c) 2018, Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
2021-01-12 07:12:03 +01:00
|
|
|
name: onepassword_raw
|
2020-03-09 10:11:07 +01:00
|
|
|
author:
|
|
|
|
- Scott Buchanan (@scottsb)
|
|
|
|
- Andrew Zenk (@azenk)
|
|
|
|
- Sam Doran (@samdoran)
|
|
|
|
requirements:
|
2023-11-26 20:32:20 +01:00
|
|
|
- C(op) 1Password command line utility
|
|
|
|
short_description: Fetch an entire item from 1Password
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
2023-06-10 09:28:40 +02:00
|
|
|
- P(community.general.onepassword_raw#lookup) wraps C(op) command line utility to fetch an entire item from 1Password.
|
2020-03-09 10:11:07 +01:00
|
|
|
options:
|
|
|
|
_terms:
|
2023-11-26 20:32:20 +01:00
|
|
|
description: Identifier(s) (case-insensitive UUID or name) of item(s) to retrieve.
|
2022-09-06 20:42:17 +02:00
|
|
|
required: true
|
2024-07-21 22:16:02 +02:00
|
|
|
type: list
|
|
|
|
elements: string
|
2023-09-28 21:26:49 +02:00
|
|
|
account_id:
|
|
|
|
version_added: 7.5.0
|
2023-11-26 20:32:20 +01:00
|
|
|
domain:
|
|
|
|
version_added: 6.0.0
|
2023-06-15 19:18:12 +02:00
|
|
|
service_account_token:
|
|
|
|
version_added: 7.1.0
|
2023-11-26 20:32:20 +01:00
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.onepassword
|
|
|
|
- community.general.onepassword.lookup
|
2020-03-09 10:11:07 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
- name: Retrieve all data about Wintermute
|
2020-07-14 17:28:08 +02:00
|
|
|
ansible.builtin.debug:
|
2020-08-08 22:04:34 +02:00
|
|
|
var: lookup('community.general.onepassword_raw', 'Wintermute')
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
- name: Retrieve all data about Wintermute when not signed in to 1Password
|
2020-07-14 17:28:08 +02:00
|
|
|
ansible.builtin.debug:
|
2020-08-08 22:04:34 +02:00
|
|
|
var: lookup('community.general.onepassword_raw', 'Wintermute', subdomain='Turing', vault_password='DmbslfLvasjdl')
|
2020-03-09 10:11:07 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
RETURN = """
|
|
|
|
_raw:
|
2023-11-26 20:32:20 +01:00
|
|
|
description: Entire item requested.
|
2020-09-16 11:06:45 +02:00
|
|
|
type: list
|
|
|
|
elements: dict
|
2020-03-09 10:11:07 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
from ansible_collections.community.general.plugins.lookup.onepassword import OnePass
|
|
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
|
|
|
|
|
|
|
|
class LookupModule(LookupBase):
|
|
|
|
|
|
|
|
def run(self, terms, variables=None, **kwargs):
|
2022-11-06 11:32:35 +01:00
|
|
|
self.set_options(var_options=variables, direct=kwargs)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2022-11-06 11:32:35 +01:00
|
|
|
vault = self.get_option("vault")
|
|
|
|
subdomain = self.get_option("subdomain")
|
|
|
|
domain = self.get_option("domain", "1password.com")
|
|
|
|
username = self.get_option("username")
|
|
|
|
secret_key = self.get_option("secret_key")
|
|
|
|
master_password = self.get_option("master_password")
|
2023-06-15 19:18:12 +02:00
|
|
|
service_account_token = self.get_option("service_account_token")
|
2023-09-28 21:26:49 +02:00
|
|
|
account_id = self.get_option("account_id")
|
2023-11-16 20:57:11 +01:00
|
|
|
connect_host = self.get_option("connect_host")
|
|
|
|
connect_token = self.get_option("connect_token")
|
|
|
|
|
2023-11-26 20:32:20 +01:00
|
|
|
op = OnePass(
|
|
|
|
subdomain=subdomain,
|
|
|
|
domain=domain,
|
|
|
|
username=username,
|
|
|
|
secret_key=secret_key,
|
|
|
|
master_password=master_password,
|
|
|
|
service_account_token=service_account_token,
|
|
|
|
account_id=account_id,
|
|
|
|
connect_host=connect_host,
|
|
|
|
connect_token=connect_token,
|
|
|
|
)
|
2020-03-09 10:11:07 +01:00
|
|
|
op.assert_logged_in()
|
|
|
|
|
|
|
|
values = []
|
|
|
|
for term in terms:
|
|
|
|
data = json.loads(op.get_raw(term, vault))
|
|
|
|
values.append(data)
|
2022-11-06 11:32:35 +01:00
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
return values
|