'site_env' is undefined

I’ve updated my trellis clone to the latest version, but now get this error ‘site_env’ is undefined when I run ansible-playbook -vvvv server.yml -e env=staging.

TASK [wordpress-setup : Create database of sites] ******************************
task path: /home/ivan/dev/moje/fapps/trellis/roles/wordpress-setup/tasks/database.yml:2
System info:
Ansible 2.0.1.0; Linux
Trellis 0.9.7: April 10th, 2016

‘site_env’ is undefined
fatal: [46.101.240.80]: FAILED! => {“failed”: true}
to retry, use: --limit @server.retry

It’s likely that something was missed during the update process. Maybe you had merge conflicts to fix and something was forgotten?

I’m getting this as well while trying to run vagrant provision to re-provision my local env.

TASK [wordpress-setup : Create database of sites] ****************************** fatal: [default]: FAILED! => {"failed": true, "msg": "The conditional check 'site_uses_local_db and item.value.db_create | default(True)' failed. The error was: error while evaluating conditional (site_uses_local_db and item.value.db_create | default(True)): 'site_env' is undefined\n\nThe error appears to have been in '***/trellis/roles/wordpress-setup/tasks/database.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Create database of sites\n ^ here\n"} to retry, use: --limit @***/trellis/dev.retry

My reply above applies to you as well.

site_env exists here. Make sure you have it.

2 Likes

@swalkinshaw I’m getting the same /similar error.in trellis as at 28/2/17 You link to a file in /group_vars/all but it doesnt say in the docs to edit that file with that line. Can this go in /staging/main.yml?

TASK [wordpress-setup : Create database of sites] ******************************
System info:
  Ansible 2.2.1.0; Darwin
  Trellis at "Allow for per-project packagist.com authentication"


The conditional check 'site_uses_local_db and item.value.db_create |
default(True)' failed. The error was: error while evaluating conditional
(site_uses_local_db and item.value.db_create | default(True)): {{
site_env.db_host == 'localhost' }}: {{ wordpress_env_defaults |
combine(item.value.env | default({}), vault_wordpress_sites[item.key].env)
}}: 'unicode object' has no attribute u'staging.sliponjohn.band'

The error appears to have been in
'/Users/lukemackenzie/Sites/sliponjohn.band/trellis/roles/wordpress-
setup/tasks/database.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Create database of sites
  ^ here

fatal: [staging.sliponjohn.band]: FAILED! => {"failed": true}

Or do I need to have these defined in staging/wordpress_sites.yml?:

  mysql_db:
    name: "{{ site_env.db_name }}"
    state: present
    login_host: "{{ site_env.db_host }}"
    login_user: "{{ mysql_root_user }}"
    login_password: "{{ mysql_root_password }}"
  with_dict: "{{ wordpress_sites }}"

You don’t have the same error.

Your error says:

vault_wordpress_sites[item.key].env)
}}: ‘unicode object’ has no attribute u’staging.sliponjohn.band’

You need to configure your sites + vault properly according to the docs: https://roots.io/trellis/docs/wordpress-sites/#passwordssecrets

2 Likes

Thanks. Turns out it was a typo invault.yaml which the parser didn’t pick up. YAML, oh how I hate thee :frowning: