# How to execute AWS CLI command which is stored in variable from ansible playbook

**URL:** <https://forum.ansible.com/t/how-to-execute-aws-cli-command-which-is-stored-in-variable-from-ansible-playbook/41031>\
**Category:** Get Help\
**Tags:** aws\
**Created:** [March 13, 2025, 3:58pm UTC](https://forum.ansible.com/t/how-to-execute-aws-cli-command-which-is-stored-in-variable-from-ansible-playbook/41031 "2025-03-13T15:58:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Madan\_Kumar\_Dusarlap](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/madan_kumar_dusarlap/32/7731_2.png) [@Madan\_Kumar\_Dusarlap](https://forum.ansible.com/u/Madan_Kumar_Dusarlap)\
**Post date:** [March 13, 2025, 3:58pm UTC](https://forum.ansible.com/t/how-to-execute-aws-cli-command-which-is-stored-in-variable-from-ansible-playbook/41031/1 "2025-03-13T15:58:43Z")

</div>

How to execute AWS CLI command dynamically that is stored in variable of ansible playbook. Please share respective ansible script.

Server has AWS CLI utility that is in below path  
path: /usr/local/bin/aws

ansibledba is the OS user which need to run the ansbible playbook using sudo command

---

<div class="post-metadata">

**Author:** ![hugonz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hugonz/32/503_2.png) [@hugonz](https://forum.ansible.com/u/hugonz)\
**Post date:** [March 13, 2025, 6:00pm UTC](https://forum.ansible.com/t/how-to-execute-aws-cli-command-which-is-stored-in-variable-from-ansible-playbook/41031/2 "2025-03-13T18:00:19Z")

</div>

You can do that, but instead of running a custom aws command from a variable, you should see if the aws collection has a module for what you’re trying to do.

```auto
- hosts: all
  vars:
    custom_awscli_command: somecommand
  tasks:
    - name: Run variable command
      ansible.builtin.shell:
        cmd: /usr/local/bin/aws {{ custom_awscli_command }}

```
