Deploy fails at WordPress setup task

After

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
group_vars/production/wordpress_sites.yml
and I can’t find what I am doing wrong.

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

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

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/Users/aitor/server.retry

abralaboca.net             : 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: https://github.com/roots/trellis#wordpress-sites
wordpress_sites:
  admin_password: my_paswrd
  abralaboca.net:
    site_hosts:
      - abralaboca.net
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    repo: git@github.com:roots/bedrock.git
    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)
    multisite:
      enabled: false
      subdomains: false
    ssl:
      enabled: false
    cache:
      enabled: false
      duration: 30s
    system_cron: true
    env:
      wp_home: http://abralaboca.net
      wp_siteurl: http://abralaboca.net/wp
      wp_env: production
      db_name: abralaboca
      db_user: aitor
      db_password: my_db_paswrd
      # Generate your keys here: https://api.wordpress.org/secret-key/1.1/salt/
      # 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 abralaboca.net. 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 another-site.com, and it would have all the subelements like you have for abralaboca.net. 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

Congratulations!

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 ./deploy.sh production abralaboca.net and then navigate to abralaboca.net 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.

2 Likes

Wow! It works! Let me express my happiness.

One final question. I have Sage theme at dev environment, I can see it at abralaboca.dev 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:
    repo: git@github.com:roots/bedrock.git
    to:
    repo: git@github.com:aitormendez/abralaboca.git
  • 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:

http://abralaboca.net/

2 Likes