|
7 | 7 | short_description: create or update a credential to DVLS |
8 | 8 |
|
9 | 9 | description: |
10 | | - - This module logs into the DVLS (Devolutions Server) service, checks if a entry inside a given path already exists and updates or creates a Credential by name. |
11 | | - - The module requires DVLS application credentials, a server base URL and the data needed to create a secret. |
| 10 | + - Logs into the DVLS (Devolutions Server) service, checks if an entry exists at a given path, and updates or creates a Credential by name. |
| 11 | + - Requires DVLS application credentials, a server base URL and the data needed to create a secret. |
12 | 12 |
|
13 | 13 | options: |
14 | 14 | server_base_url: |
|
30 | 30 | secret: |
31 | 31 | description: the credential object, containing username and password. |
32 | 32 | required: true |
33 | | - type: list |
34 | | - elements: dict |
| 33 | + type: dict |
35 | 34 | suboptions: |
36 | 35 | secret_name: |
37 | 36 | description: the entry name/username. |
|
49 | 48 | description: the type of secret that will get created. |
50 | 49 | required: false |
51 | 50 | type: str |
52 | | - default: Credentials |
| 51 | + default: Credential |
53 | 52 | secret_subtype: |
54 | 53 | description: the secret subtype. |
55 | 54 | required: false |
|
65 | 64 | """ |
66 | 65 |
|
67 | 66 | EXAMPLES = r""" |
68 | | -- name: Upload Credentials to DVLS |
| 67 | +- name: Upload Credential to DVLS |
69 | 68 | devolutions.dvls.create_secret: |
70 | 69 | server_base_url: "https://example.yourcompany.com" |
71 | 70 | app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" |
|
82 | 81 | description: returns the ID of the created/updated entry. |
83 | 82 | type: dict |
84 | 83 | returned: changed |
| 84 | +
|
85 | 85 | """ |
86 | 86 |
|
87 | | -from ansible.module_utils.basic import AnsibleModule |
| 87 | +import traceback |
| 88 | + |
| 89 | +from ansible.module_utils.basic import AnsibleModule, missing_required_lib |
88 | 90 | from ansible_collections.devolutions.dvls.plugins.module_utils.auth import login, logout |
89 | 91 | from ansible_collections.devolutions.dvls.plugins.module_utils.vaults import ( |
90 | 92 | get_vault_entries, |
91 | 93 | find_entry_by_name, |
92 | 94 | ) |
93 | | -import requests |
| 95 | + |
| 96 | +try: |
| 97 | + import requests |
| 98 | +except ImportError: |
| 99 | + HAS_REQUESTS_LIBRARY = False |
| 100 | + REQUESTS_LIBRARY_IMPORT_ERROR = traceback.format_exc() |
| 101 | +else: |
| 102 | + HAS_REQUESTS_LIBRARY = True |
| 103 | + REQUESTS_LIBRARY_IMPORT_ERROR = None |
94 | 104 |
|
95 | 105 |
|
96 | 106 | def run_module(): |
97 | | - module_args = dict( |
| 107 | + argument_spec = dict( |
98 | 108 | server_base_url=dict(type="str", required=True), |
99 | | - app_key=dict(type="str", required=True), |
100 | | - app_secret=dict(type="str", required=True), |
| 109 | + app_key=dict(type="str", required=True, no_log=True), |
| 110 | + app_secret=dict(type="str", required=True, no_log=True), |
101 | 111 | vault_id=dict(type="str", required=True), |
102 | 112 | secret=dict( |
103 | 113 | type="dict", |
104 | 114 | options=dict( |
105 | | - secret_name=dict(type="str", required=True), |
106 | | - value=dict(type="str", required=True), |
107 | | - secret_path=dict(type="str", required=False), |
108 | | - secret_type=dict(type="str", required=False, default="Credential"), |
109 | | - secret_subtype=dict(type="str", required=False, default="Default"), |
110 | | - secret_description=dict(type="str", required=False), |
| 115 | + secret_name=dict(type="str", required=True, no_log=False), |
| 116 | + value=dict(type="str", required=True, no_log=True), |
| 117 | + secret_path=dict(type="str", required=False, no_log=False), |
| 118 | + secret_type=dict( |
| 119 | + type="str", required=False, default="Credential", no_log=False |
| 120 | + ), |
| 121 | + secret_subtype=dict( |
| 122 | + type="str", required=False, default="Default", no_log=False |
| 123 | + ), |
| 124 | + secret_description=dict(type="str", required=False, no_log=False), |
111 | 125 | ), |
112 | 126 | required=True, |
| 127 | + no_log=False, |
113 | 128 | ), |
114 | 129 | ) |
115 | 130 |
|
116 | 131 | result = dict() |
117 | 132 |
|
118 | | - module = AnsibleModule(argument_spec=module_args, supports_check_mode=True) |
| 133 | + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) |
| 134 | + |
| 135 | + if not HAS_REQUESTS_LIBRARY: |
| 136 | + module.fail_json( |
| 137 | + msg=missing_required_lib("requests"), |
| 138 | + exception=REQUESTS_LIBRARY_IMPORT_ERROR, |
| 139 | + ) |
119 | 140 |
|
120 | 141 | if module.check_mode: |
121 | 142 | module.exit_json(**result) |
|
0 commit comments