# Use aws cli to start AWS workspaces via AWX

**URL:** <https://forum.ansible.com/t/use-aws-cli-to-start-aws-workspaces-via-awx/7020>\
**Category:** Get Help\
**Tags:** amazon-linux-2, ubuntu, awx, aws\
**Created:** [July 3, 2024, 3:42pm UTC](https://forum.ansible.com/t/use-aws-cli-to-start-aws-workspaces-via-awx/7020 "2024-07-03T15:42:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Merlin1990](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/merlin1990/32/3965_2.png) [@Merlin1990](https://forum.ansible.com/u/Merlin1990)\
**Post date:** [July 3, 2024, 3:42pm UTC](https://forum.ansible.com/t/use-aws-cli-to-start-aws-workspaces-via-awx/7020/1 "2024-07-03T15:42:50Z")

</div>

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:

```auto
- 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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![tima](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tima/32/854_2.png) [@tima](https://forum.ansible.com/u/tima)\
**Post date:** [July 3, 2024, 4:18pm UTC](https://forum.ansible.com/t/use-aws-cli-to-start-aws-workspaces-via-awx/7020/2 "2024-07-03T16:18:45Z")

</div>

You’re getting a 127 return code which is command not found. I’d venture a guess that the AWX linux user/environment does not have `aws` in it’s $PATH to just find it as you’ve written your tasks. Create a task that just does `aws --version` and run it in AWX. Do you still get an error? If you do, then it is the path to `aws` from your AWX user account when executing your playbook.

---

<div class="post-metadata">

**Author:** ![Merlin1990](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/merlin1990/32/3965_2.png) [@Merlin1990](https://forum.ansible.com/u/Merlin1990)\
**Post date:** [July 4, 2024, 8:06am UTC](https://forum.ansible.com/t/use-aws-cli-to-start-aws-workspaces-via-awx/7020/3 "2024-07-04T08:06:00Z")

</div>

ah okay, i get this:

```auto
TASK [Check AWS CLI version] *************************************************** 10:01:23

4

fatal: [localhost]: FAILED! => {"changed": false, "cmd": "aws --version", "msg": "[Errno 2] No such file or directory: b'aws'", "rc": 2, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

5

...ignoring

```

thats weird, because on the Execution Environment itself it works:

```auto
[root@test-ee bin]# aws --version

aws-cli/2.17.5 Python/3.11.8 Linux/4.18.0-552.3.1.el8.x86_64 exe/x86_64.centos.9

```

if i use “localhost” as deligate or hosts, does it try to execute this on the EE i selected or on the AWX host himself? 🤔

---

<div class="post-metadata">

**Author:** ![Merlin1990](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/merlin1990/32/3965_2.png) [@Merlin1990](https://forum.ansible.com/u/Merlin1990)\
**Post date:** [July 16, 2024, 7:20am UTC](https://forum.ansible.com/t/use-aws-cli-to-start-aws-workspaces-via-awx/7020/4 "2024-07-16T07:20:43Z")

</div>

Small Update/Fix: aws cli was installed on the wrong EE (i did not used) 🤦‍♂️

but thanks for reply!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 15, 2024, 7:20am UTC](https://forum.ansible.com/t/use-aws-cli-to-start-aws-workspaces-via-awx/7020/5 "2024-08-15T07:20:48Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
