Skip to content

Commit

Permalink
Added possibility to pass arguments to task invocation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Barbun committed Nov 25, 2024
1 parent c4bf3b8 commit 95a04ab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/plugins/action/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def run(self, tmp=None, task_vars=None):
environment_ns = self._task.args.get("environment")
environment_id = self._task.args.get("environment_id")
task_name = self._task.args.get("name")
task_arguments = self._task.args.get("arguments")

if not task_name:
raise AnsibleOptionsError("Task name is required")
Expand Down Expand Up @@ -47,5 +48,5 @@ def run(self, tmp=None, task_vars=None):

# Invoke the task.
result["changed"] = True
result['task_id'] = Task(self.client).invoke(environment_id, task_id)
result['task_id'] = Task(self.client).invoke(environment_id, task_id, task_arguments)
return result
5 changes: 4 additions & 1 deletion api/plugins/module_utils/gqlTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,24 @@ def byId(self, id: int, fields: List[str] = None) -> dict:

return res

def invoke(self, env_id: int, task_id: int) -> int:
def invoke(self, env_id: int, task_id: int, task_arguments: list) -> int:
res = self.client.execute_query(
f"""
mutation InvokeTask(
$env_id: Int!
$task_id: Int!
$task_arguments: [AdvancedTaskDefinitionArgumentValueInput]
) {{
invokeRegisteredTask(
environment: $env_id,
advancedTaskDefinition: $task_id,
argumentValues: $task_arguments,
) {{ id }}
}}""",
{
"env_id": env_id,
"task_id": task_id,
"task_arguments": task_arguments,
}
)
return res['invokeRegisteredTask']['id']
Expand Down
21 changes: 21 additions & 0 deletions api/plugins/modules/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
- Name of the task to invoke.
type: str
required: true
arguments:
description:
- The arguments to execute the command with
type: list
elements: dict
suboptions:
advancedTaskDefinitionArgumentName:
description:
- The name of the argument.
required: true
type: string
value:
description:
- The value of the argument.
required: true
type: string
'''

Expand All @@ -27,6 +43,11 @@
lagoon.api.task:
environment: test-shipshape-master
name: AUDIT - Admin shipshape
arguments:
- advancedTaskDefinitionArgumentName: ARG1
value: VALUE1
- advancedTaskDefinitionArgumentName: ARG2
value: VALUE2
register: task_result
- name: Display the task id
debug: var=task_result.task_id
Expand Down

0 comments on commit 95a04ab

Please sign in to comment.