Skip to content

Commit 8bbe503

Browse files
committed
chore: add debug example for vscode
1 parent ce87e4f commit 8bbe503

File tree

6 files changed

+129
-4
lines changed

6 files changed

+129
-4
lines changed

plugins/modules/fetch_secrets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494

9595

9696
def run_module():
97-
module_args = dict(
97+
argument_spec = dict(
9898
server_base_url=dict(type="str", required=True),
9999
app_key=dict(type="str", required=True, no_log=True),
100100
app_secret=dict(type="str", required=True, no_log=True),
@@ -116,7 +116,7 @@ def run_module():
116116

117117
result = dict()
118118

119-
module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
119+
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
120120

121121
if module.check_mode:
122122
module.exit_json(**result)

plugins/modules/fetch_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@
5454

5555

5656
def run_module():
57-
module_args = dict(
57+
argument_spec = dict(
5858
server_base_url=dict(type="str", required=True),
5959
app_key=dict(type="str", required=True, no_log=True),
6060
app_secret=dict(type="str", required=True, no_log=True),
6161
)
6262

6363
result = dict()
6464

65-
module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
65+
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
6666

6767
if module.check_mode:
6868
module.exit_json(**result)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copy this in the .vscode folder of your project to debug your module
2+
3+
import sys
4+
import os
5+
import io
6+
import json
7+
8+
# Wrap arguments under ANSIBLE_MODULE_ARGS
9+
mock_args = {
10+
"ANSIBLE_MODULE_ARGS": {
11+
"server_base_url": os.getenv("DVLS_SERVER_BASE_URL"),
12+
"app_key": os.getenv("DVLS_APP_KEY"),
13+
"app_secret": os.getenv("DVLS_APP_SECRET"),
14+
"vault_id": os.getenv("DVLS_VAULT_ID"),
15+
"secret": {
16+
"secret_name": "test",
17+
"value": "test"
18+
}
19+
}
20+
}
21+
22+
# Convert to bytes, wrap for stdin
23+
input_bytes = json.dumps(mock_args).encode("utf-8")
24+
sys.stdin = io.TextIOWrapper(io.BytesIO(input_bytes), encoding="utf-8")
25+
26+
# Import and run your module
27+
from ansible_collections.devolutions.dvls.plugins.modules import create_secret
28+
create_secret.main()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copy this in the .vscode folder of your project to debug your module
2+
3+
import sys
4+
import os
5+
import io
6+
import json
7+
8+
# Wrap arguments under ANSIBLE_MODULE_ARGS
9+
mock_args = {
10+
"ANSIBLE_MODULE_ARGS": {
11+
"server_base_url": os.getenv("DVLS_SERVER_BASE_URL"),
12+
"app_key": os.getenv("DVLS_APP_KEY"),
13+
"app_secret": os.getenv("DVLS_APP_SECRET"),
14+
"vault_id": os.getenv("DVLS_VAULT_ID"),
15+
}
16+
}
17+
18+
# Convert to bytes, wrap for stdin
19+
input_bytes = json.dumps(mock_args).encode("utf-8")
20+
sys.stdin = io.TextIOWrapper(io.BytesIO(input_bytes), encoding="utf-8")
21+
22+
# Import and run your module
23+
from ansible_collections.devolutions.dvls.plugins.modules import fetch_secrets
24+
fetch_secrets.main()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copy this in the .vscode folder of your project to debug your module
2+
3+
import sys
4+
import os
5+
import io
6+
import json
7+
8+
# Wrap arguments under ANSIBLE_MODULE_ARGS
9+
mock_args = {
10+
"ANSIBLE_MODULE_ARGS": {
11+
"server_base_url": os.getenv("DVLS_SERVER_BASE_URL"),
12+
"app_key": os.getenv("DVLS_APP_KEY"),
13+
"app_secret": os.getenv("DVLS_APP_SECRET")
14+
}
15+
}
16+
17+
# Convert to bytes, wrap for stdin
18+
input_bytes = json.dumps(mock_args).encode("utf-8")
19+
sys.stdin = io.TextIOWrapper(io.BytesIO(input_bytes), encoding="utf-8")
20+
21+
# Import and run your module
22+
from ansible_collections.devolutions.dvls.plugins.modules import fetch_server
23+
fetch_server.main()

tests/debug/vscode/launch.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug - fetch_server.py",
6+
"type": "debugpy",
7+
"request": "launch",
8+
"program": "${workspaceFolder}/.vscode/debug_fetch_server.py",
9+
"console": "integratedTerminal",
10+
"env": {
11+
"DVLS_SERVER_BASE_URL": "<url>",
12+
"DVLS_APP_KEY": "<app-key>",
13+
"DVLS_APP_SECRET": "<app-secret>",
14+
"DVLS_VAULT_ID": "<vault-id>",
15+
"PYTHONPATH": "/Users/<user>/dev/git/ansible"
16+
},
17+
"justMyCode": false
18+
},
19+
{
20+
"name": "Debug - fetch_secrets.py",
21+
"type": "debugpy",
22+
"request": "launch",
23+
"program": "${workspaceFolder}/.vscode/debug_fetch_secrets.py",
24+
"console": "integratedTerminal",
25+
"env": {
26+
"DVLS_SERVER_BASE_URL": "<url>",
27+
"DVLS_APP_KEY": "<app-key>",
28+
"DVLS_APP_SECRET": "<app-secret>",
29+
"DVLS_VAULT_ID": "<vault-id>",
30+
"PYTHONPATH": "/Users/<user>/dev/git/ansible"
31+
},
32+
"justMyCode": false
33+
},
34+
{
35+
"name": "Debug - create_secrets.py",
36+
"type": "debugpy",
37+
"request": "launch",
38+
"program": "${workspaceFolder}/.vscode/debug_create_secrets.py",
39+
"console": "integratedTerminal",
40+
"env": {
41+
"DVLS_SERVER_BASE_URL": "<url>",
42+
"DVLS_APP_KEY": "<app-key>",
43+
"DVLS_APP_SECRET": "<app-secret>",
44+
"DVLS_VAULT_ID": "<vault-id>",
45+
"PYTHONPATH": "/Users/<user>/dev/git/ansible"
46+
},
47+
"justMyCode": false
48+
}
49+
]
50+
}

0 commit comments

Comments
 (0)