Deploy fails at WordPress setup task


ansible-playbook -i hosts/production server.yml --ask-become-pass

I got the error at the end of deploy. This is the terminal ouput tail. I have checked again and again
and I can’t find what I am doing wrong.

TASK: [wordpress-setup | Create database of sites] **************************** 

fatal: [] => One or more undefined variables: 'str object' has no attribute 'env'

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/Users/aitor/server.retry             : ok=75   changed=2    unreachable=1    failed=0

Does your group_vars/production/wordpress_sites.yml file have this .env section? It should.

If the .env section is present, I suspect there is a yaml formatting problem. You could paste your entire group_vars/production/wordpress_sites.yml file here for us to inspect. Please edit out sensitive info like passwords before you submit your reply.

1 Like

Thank you! Here is:

(I triyed uncommenting subtree_path: site too with same results)

# Documentation:
  admin_password: my_paswrd
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    branch: master
    # subtree_path: site # relative path to your Bedrock/WP directory in your repo (above) if it is not the root (like the roots-example-project structure)
      enabled: false
      subdomains: false
      enabled: false
      enabled: false
      duration: 30s
    system_cron: true
      wp_env: production
      db_name: abralaboca
      db_user: aitor
      db_password: my_db_paswrd
      # Generate your keys here:
      # These CANNOT contain the characters "{%" in succession
      auth_key: "0bS$d/,}{)      ...ETC (salt generated)"
      secure_auth_key: "~2[      ...ETC (salt generated)"
      logged_in_key: "v(Ts:      ...ETC (salt generated)"
      nonce_key: "X^8{2G5+<      ...ETC (salt generated)"
      auth_salt: "jVABU^6X}      ...ETC (salt generated)"
      secure_auth_salt: "E/      ...ETC (salt generated)"
      logged_in_salt: "qN~$      ...ETC (salt generated)"
      nonce_salt: "^0J~;Zu[      ...ETC (salt generated)"

Try removing the line with admin_password and rerunning server.yml.

The admin_password variable appears only in the development wordpress_sites, not in staging or production wordpress_sites. Looks like the README does mention “development only” for admin_password, but that would be easy to miss.

No need to understand the rest of this, but the error 'str object' has no attribute 'env' occurred when “Create database of sites” looped over the hierarchically topmost elements of wordpress_sites: admin_password and The element admin_password doesn’t have the env subelement called for.

The element admin_password should not appear in this list, especially not at this level (hierarchically). The only other element at this level would be, and it would have all the subelements like you have for You would use that if you wanted your one server to serve two sites (or more).

Let us know if that resolves the issue. If something else comes up, feel free to open a separate issue.

It works. Thank you very much for the fix and explanation too. It deploys now untill end without errors.

I have now a 404 Nginx error at my URL, but I will ask in a separate issue, as you suggest.

1 Like


Re: your 404, you probably just need to deploy the site now. Trellis runs dev.yml on the Vagrant VM, which includes the wordpress-install role. For staging and production, server.yml doesn’t include this role.

Try running ./ production and then navigate to in your browser. You should then see the wordpress install screen.

If that fails, debug for a bit and post a new issue if you’d like extra help.


Wow! It works! Let me express my happiness.

One final question. I have Sage theme at dev environment, I can see it at when I do vagrant up, but Sage is not present at remote server. why?

Vagrant is probably syncing your theme between your host machine and the vm, so the dev site/server sees the theme files.

You’ll need to find a way to get your theme on the remote production server. For ideas, see this post addressing the question of “What approach are you taking to deploying your theme?”

1 Like

So, if I understand correctly, I should do:

  • Open a repo abralaboca on GitHub
  • Git init on my local root project folder and commit/push it to origin master (including site and ansible folders)
  • At group_vars/production/wordpress_sites.yml, change:
  • Uncomment subtree_path: site at group_vars/production/wordpress_sites.yml
  • Deploy again

Is it?

I answer myself: It works. I need to delete .git directories at ansible, site and sage folders in order to Github doesn’t see it as subprojects.

Great! Your steps appear correct as I glance over them, although I didn’t compare step-by-step with the README or with the docs.

One thing you’ll probably need to address, if you haven’t already, is how to get your theme’s compiled assets on the server. The dist directory typically wouldn’t be committed to your repo and thus wouldn’t be retrieved when the deploy clones the repo.

The recommended approach is to compile the assets on your local machine (gulp --production) then have the deploy sync the dist directory to your remote server. As @swalkinshaw recommended here, add this line to your deploy.yml:

deploy_build_before: "{{ playbook_dir }}/deploy-hooks/build-before.yml"

Then create a deploy-hooks directory in your ansible directory, with a build-before.yml file that has contents similar to what @swalkinshaw listed at the link above. Decide which tasks to include. At a minimum, I think you’d want the last task - name: Copy project local files. You’ll want to adjust the paths for your theme name, etc.

That’s a little complex but charge through it and I think you’ll continue understanding it as well as you’ve done with the other steps before this.

1 Like

Yes, indeed, WP theme is actually served without CSS and other dist files. That’s my next learning step. Thank you for your guide and your time.

Done! It works :grinning: