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 }}”