Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEVOPS-350] Added possibility to pass arguments to task invocation. #103

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading