Include ansible tasks file from within a deploy hook

Hi there,

i want to configure wordpress (activate correct theme, plugins, …) on every deploy. so i added a wp-config.yml file to /trellis/deploy-hooks:

- name: Activate Sage Theme
  command: wp theme activate sage
    chdir: "{{ deploy_helper.new_release_path }}"

- name: Create main menu if not already there
  command: wp menu create main
    chdir: "{{ deploy_helper.new_release_path }}"
  ignore_errors: yes

When I include that file in the modified deploy hook /trellis/deploy-hooks/finalize-after.yml:


- name: Update WP network database
  command: wp core update-db --network
    chdir: "{{ deploy_helper.new_release_path }}"
  when: wp_installed | success and project.multisite.enabled | default(false)

- include: wp-config.yml

- name: Reload php-fpm
  shell: killall php-cgi
    chdir: "{{ deploy_helper.new_release_path }}"
    warn: false
  ignore_errors: True

… then the deploy run silently stops (no fail) with the not executed include step. Here’s the output:

TASK [deploy : Update WP database] *********************************************
changed: []

TASK [deploy : Warn about updating network database.] **************************
skipping: []

TASK [deploy : Update WP network database] *************************************
skipping: []

TASK [deploy : include] ********************************************************

PLAY RECAP *********************************************************************        : ok=33   changed=14   unreachable=0    failed=0
localhost                  : ok=0    changed=0    unreachable=0    failed=0

Anyone any idea, what’s going wrong here?

Thanks for your help,

Maybe it would help Ansible find the include file if you were more explicit about the path, like this example

- - include: wp-config.yml
+ - include: "{{ playbook_dir }}/deploy-hooks/wp-config.yml"

I vaguely remember the Ansible docs mentioning the relative paths that will be checked for include files, so I think the info is there if you end up needing to search for it.

Unfortunately @fullyint’s suggestion is unlikely to work too. I suspect it’s an issue with Ansible and nested includes. Not only does the included playbook fail to run, but any tasks after it do not run. I recommend for now that you include the tasks you want to run directly (which I can confirm works).

I only did a brief search of Ansible issues and couldn’t find anything relevant but perhaps a more detailed search will turn up something. Or, create an issue.

no, that doesn’t help. i already had tried that and just once again => silent fail.

i think it has to do with the fact, that i include it in an already included task/hook file. when i include it directly from within /trellis/roles/deploy/tasks/finalize.yml it works. but then i have to rewrite the original tasks, which seems like a workaround. i guess i will go with this solution.

thanks @fullyint for your immediate help!