Modified deploy.sh to accept a third argument. Ansible fails

Hello,

I’ve been working with bedrock-ansible and bedrock have a different folder structure than suggested in bedrock-ansible docs.

I changed deploy.sh script to accept a thirs argument:

DEPLOY_CMD="ansible-playbook -i hosts/$1 deploy.yml --extra-vars="site=$2 theme=$3""

Then I wanted to utilize the {{ theme }} variable here:

project_pre_build_commands_local:
   - path: "{{ project.local_path }}/web/app/themes/{{ theme }}"
     cmd: npm install
   - path: "{{ project.local_path }}/web/app/themes/{{ theme }}"
     cmd: bower install
   - path: "{{ project.local_path }}/web/app/themes/{{ theme }}"
     cmd: gulp --production

This way I cen run build command from one bedrock-ansible install for every site separately and there are no directory confilicts.

However, the shell errors out:

msg: cannot change to directory ‘/home/ltarasiewicz/dev/bedrock-stack/bedrock-ansible/{# project.local_path #}/web/app/themes/{# theme #}’: path does not exist

As soon as I remove {{ theme }} from paths in project_pre_build_commands_local, everything is back to normal. {{ project.local_path }} is interpreted correctly.

What am I missing here? Why am I not able to pass the {{ theme }} parameter to my Ansible commands?

I know what the problem was, in case anybody reads this in the future.
I’ve been trying to use theme variable in a file different that the playbook called within deploy.sh. Variables passed with --extra-vars are by no means globally available to all Ansible files, only to the file it was called with in ansible-playbook commans… same basic Ansible staff…

2 Likes

@luqo33 How about adding a theme variable under each site in wordpress_sites, for example:

wordpress_sites:
  example.com:
    site_hosts:
      - example.com
    local_path: ../site
    theme: mytheme
    ⋮

The deploy.yml playbook loads the site variables in project dict, so use {{ project.theme }}:

project_pre_build_commands_local:
  - path: "{{ project.local_path }}/web/app/themes/{{ project.theme }}"
    ⋮

Then you don’t even have to type in the theme name on each deploy.

This is exactly what I ended up doing, and now it’s working great. I can have one ansible-bedrock copy and deploy several sites with it independent from one another.