Trellis deploy to production fails at TASK [deploy : Copy project templates]

Deploying to production the process fails with the following error:

TASK [deploy : Copy project templates] *****************************************
changed: [12.34.567.891] => (item={'name': '.env config', 'src': 'roles/deploy/templates/env.j2', 'dest': '.env', 'mode': '0600'})
---------------------------------------------------
The task includes an option with an undefined variable. The error was: 'dict
object' has no attribute 'dest'

The error appears to be in '/home/***/Desktop/Projects/site.com/t
rellis/roles/deploy/tasks/build.yml': line 16, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: Copy project templates
  ^ here
fatal: [12.34.567.891]: FAILED! => {}

PLAY RECAP *********************************************************************
12.34.567.891              : ok=16   changed=7    unreachable=0    failed=1    skipped=25   rescued=0    ignored=0   
localhost                  : ok=0    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

exit status 2

For reference my build.yml is the following:

---
- name: Check if deploy_build_before scripts exist
  stat:
    path: "{{ item }}"
  delegate_to: localhost
  register: deploy_build_before_paths
  with_items: "{{ deploy_build_before | default([]) }}"

- include_tasks: "{{ include_path.item }}"
  with_items: "{{ deploy_build_before_paths.results }}"
  loop_control:
    loop_var: include_path
  when: include_path.stat.exists
  tags: deploy-build-before

- name: Copy project templates
  template:
    src: "{{ item.src }}"
    dest: "{{ deploy_helper.new_release_path }}/{{ item.dest }}"
    mode: "{{ item.mode | default('0644') }}"
  with_items: "{{ project.project_templates | default(project_templates) }}"

- name: Check if project folders exist
  stat:
    path: "{{ deploy_helper.current_path }}/{{ item }}"
  register: project_folder_paths
  with_items: "{{ project.project_copy_folders | default(project_copy_folders) }}"

- name: Copy project folders
  copy:
    src: "{{ deploy_helper.current_path }}/{{ item.item }}/"
    dest: "{{ deploy_helper.new_release_path }}/{{ item.item }}"
    remote_src: true
    mode: 'preserve'
  with_items: "{{ project_folder_paths.results }}"
  when: item.stat.exists

- name: Check if deploy_build_after scripts exist
  stat:
    path: "{{ item }}"
  delegate_to: localhost
  register: deploy_build_after_paths
  with_items: "{{ deploy_build_after | default([]) }}"

- include_tasks: "{{ include_path.item }}"
  with_items: "{{ deploy_build_after_paths.results }}"
  loop_control:
    loop_var: include_path
  when: include_path.stat.exists
  tags: deploy-build-after

I’m using Ansible 2.10.16. Could the Ansible version be the problem?

Same problem here, can’t deploy and getting the same error above. I’m using trellis-cli and I can provision production. I’m running trellis provision development now but I’m stuck on TASK [wordpress-install : Change site owner to user]

Your output contains a specific error:

The task includes an option with an undefined variable. The error was: 'dict
object' has no attribute 'dest'

Looking for dest within the task it points to (on L16), there’s this line:

- name: Copy project templates
  template:
    src: "{{ item.src }}"
    dest: "{{ deploy_helper.new_release_path }}/{{ item.dest }}"
    mode: "{{ item.mode | default('0644') }}"
  with_items: "{{ project.project_templates | default(project_templates) }}"

So {{ item.dest }} is failing. And the item comes from the variable project_templates. Here’s the default value:

You can see that a dest key is defined. Does that exist in your project? Did you overwrite project_templates anywhere?

I can confirm that my project_templates is the same as default value and i did not overwrite it.

The deploy was working fine and i got this error after reinstalling the operating system (Ubunut) and every dependency. That’s why i thought it might have been the Ansible version, even if the version installed should be supported.

I double checked everything and the code is the default hence everything should be defined.

Do you have any suggestion on how i could get out of this?

You have your own, modified Trellis code/config in a separate git branch? Then compare the upstream (unmodified) Trellis (GitHub - roots/trellis: WordPress LEMP stack with PHP 8.1, Composer, WP-CLI and more) with your own. Was something changed that shouldn’t? Or changes incorrectly merged?