# rEgarding command module issue

**URL:** <https://forum.ansible.com/t/regarding-command-module-issue/37930>\
**Category:** Ansible Project\
**Created:** [April 26, 2023, 7:14am UTC](https://forum.ansible.com/t/regarding-command-module-issue/37930 "2023-04-26T07:14:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [April 26, 2023, 7:14am UTC](https://forum.ansible.com/t/regarding-command-module-issue/37930/1 "2023-04-26T07:14:48Z")

</div>

Hi All,

The ansible playbook is

- name: “Stop {{ app\_name }}”

ansible.builtin.command: “sudo pm2 stop API && sudo pm2 delete API”

failed\_when: false

- name: Flush pm2 logs

ansible.builtin.command: “sudo pm2 flush”

failed\_when: false

- name: Remove startup script

ansible.builtin.command: “sudo pm2 unstartup”

failed\_when: false

- name: Trigger the api.yml if there are any changes

stat:

path: /apps/{{ app\_name }}/dist

register: change\_api

- name: Run task if dir has changed

debug:

msg: “Dir has changed”

when: change\_api.stat.mtime != change\_api.stat.ctime and app == “api”

- include: “website.yml”

when: app == “website”

- name: “Start {{ app\_name }}”

ansible.builtin.command: “cd /apps/{{ app\_name }}; sudo npm run start:pm2”

- name: “Save process list to dump file”

ansible.builtin.command: “sudo pm2 save”

- name: “Configure {{ app\_name }} to start on boot”

ansible.builtin.command: “sudo pm2 startup”

- debug:

msg: “Deployment has been completed. Please validate.”

The error is:

ERROR! ‘ansible.builtin.command’ is not a valid attribute for a Play

The error appears to be in ‘/Users/deploy/tasks/main.yml’: line 1, column 3, but may

be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: “Stop {{ app\_name }}”

^ here

We could be wrong, but this one looks like it might be an issue with

missing quotes. Always quote template expression brackets when they

start a value. For instance:

with\_items:

- {{ foo }}

Should be written as:

with\_items:

- “{{ foo }}”

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [April 26, 2023, 9:46am UTC](https://forum.ansible.com/t/regarding-command-module-issue/37930/2 "2023-04-26T09:46:36Z")

</div>

What you have is just a list of tasks.  
A playbook is something different, and it contains that list of tasks.  
Take a look at [https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_intro.html#playbook-syntax](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_intro.html#playbook-syntax)

---

<div class="post-metadata">

**Author:** ![Ashok-2017](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ashok-2017/32/659_2.png) [@Ashok-2017](https://forum.ansible.com/u/Ashok-2017)\
**Post date:** [April 27, 2023, 3:53am UTC](https://forum.ansible.com/t/regarding-command-module-issue/37930/3 "2023-04-27T03:53:40Z")

</div>

Hi Dick,

Noted with Thanks but I would want to execute those tasks .

How would I execute?

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [April 27, 2023, 4:52am UTC](https://forum.ansible.com/t/regarding-command-module-issue/37930/4 "2023-04-27T04:52:52Z")

</div>

> Hi Dick,
> 
> Noted with Thanks but I would want to execute those tasks .
> 
> How would I execute?

By incorporating them into a playbook.  
For which I gave you a link.
