rEgarding command module issue

107 views
Skip to first unread message

Ashok Reddy

unread,
Apr 26, 2023, 3:15:10 AM4/26/23
to ansible...@googlegroups.com
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 }}"

Dick Visser

unread,
Apr 26, 2023, 5:47:11 AM4/26/23
to ansible...@googlegroups.com
What you have is just a list of tasks.
A playbook is something different, and it contains that list of tasks.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAKRLcHghkV7G81HhGh7AUb%3D_OA6Dpm_5X2eseEcMVjRasjXPWg%40mail.gmail.com.

Ashok Reddy

unread,
Apr 26, 2023, 11:55:53 PM4/26/23
to ansible...@googlegroups.com
Hi Dick,

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

How would I execute?

Dick Visser

unread,
Apr 27, 2023, 12:53:21 AM4/27/23
to ansible...@googlegroups.com
On Thu, 27 Apr 2023 at 05:54, Ashok Reddy <ashok...@gmail.com> wrote:
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. 



--
Sent from Gmail Mobile
Reply all
Reply to author
Forward
0 new messages