Good day!
My scenario is as follows: I have a dynamic inventory which gives me the latest data from my AWS workspaces with every run. I would like to start these workspaces regularly via AWX, run updates and then stop them again.
I have written the following playbook for the start:
- name: Start AWS Workspaces (Ubuntu)
hosts: ubuntu2204workspacesstopped
gather_facts: False
tasks:
- name: Start Workspace
shell: >
aws workspaces start-workspaces --start-workspace-requests WorkspaceId={{ hostvars[inventory_hostname]['workspace_id'] }}
delegate_to: localhost
- name: Start AWS Workspaces (Amazon Linux)
hosts: amazonlinux2workspacesstopped
gather_facts: False
tasks:
- name: Start Workspace
shell: >
aws workspaces start-workspaces --start-workspace-requests WorkspaceId={{ hostvars[inventory_hostname]['workspace_id'] }}
delegate_to: localhost
if I use this locally, it works and all workspaces are started.
if i run it as a template via AWX, it tries to run the shell command on each of the hosts instead of running it from the AWX host itself:
PLAY [Start AWS Workspaces (Ubuntu)] *******************************************
TASK [Start Workspace] *********************************************************
fatal: [IP_1 -> localhost]: FAILED! => {"changed": true, "cmd": "aws workspaces start-workspaces --start-workspace-requests WorkspaceId=WorkspaceId_1\n", "delta": "0:00:00.004320", "end": "2024-07-03 15:17:20.518879", "msg": "non-zero return code", "rc": 127, "start": "2024-07-03 15:17:20.514559", "stderr": "/bin/sh: line 1: aws: command not found", "stderr_lines": ["/bin/sh: line 1: aws: command not found"], "stdout": "", "stdout_lines": []}
fatal: [IP_2 -> localhost]: FAILED! => {"changed": true, "cmd": "aws workspaces start-workspaces --start-workspace-requests WorkspaceId=WorkspaceId_2\n", "delta": "0:00:00.003953", "end": "2024-07-03 15:17:20.520235", "msg": "non-zero return code", "rc": 127, "start": "2024-07-03 15:17:20.516282", "stderr": "/bin/sh: line 1: aws: command not found", "stderr_lines": ["/bin/sh: line 1: aws: command not found"], "stdout": "", "stdout_lines": []}
...
...
...
PLAY RECAP *********************************************************************
IP_1 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
IP_2 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
...
...
...
what could be the reason for this? have I overlooked something elementary?