What is the current behavior?
Ansible server.yml playbook isn't completely OK but fails with
AnsibleUndefinedVariable: {{ mailhog_install_dir }}/mhsendmail:
'mailhog_install_dir' is undefined
fatal: [192.168.50.5]: FAILED! => {"changed": false, "failed": true}
What is the expected or desired behavior?
Ansible playbook finishes with all OK.
(delete this section if not applicable)
Please provide steps to reproduce, including full log output:
Edit:
Vagrant box ubuntu/xenial64 (on VirtualBox on Ubuntu 16.04.2).
Please describe your local environment:
Ansible version: 2.2.1.0
OS: Ubuntu 16.04.2
Vagrant version: Vagrant 1.9.1
Where did the bug happen? Development or remote servers?
Development
Additional information
trellis/group_vars/development/mail.yml:
```yml
php_sendmail_path: "{{ mailhog_install_dir }}/mhsendmail"
````
Variable mailhog_install_dir is used there and
defined in trellis/vendor/roles/mailhog/defaults/main.yml:
mailhog_install_dir: /opt/mailhog
[...]
````
Thanks for the detailed issue.
Unfortunately this is a very weird thing to run into because it shouldn't happen :( I'm not even sure what to say in terms of debugging.
Maybe delete your vendor dir and manually run again ansible-galaxy install --force -r requirements.yml -p vendor/roles again?
Or maybe re-install Ansible? Could try another version like 2.2.0
Things tried:
Removed vendor folder and repulled using ansible-galaxy.
Seems to reproduce the roles nicely, but still ends with same error.
Re-installed with a different version of ansible (2.2.0.0) and tried again.
Same error.
Vagrantfile for reproducing the issue:
Vagrant.configure("2") do |config|
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = true
config.hostmanager.ignore_private_ip = true
config.hostmanager.include_offline = false
config.vm.hostname = "web"
config.hostmanager.ip_resolver = proc do |machine|
result = ""
machine.communicate.execute("ifconfig enp0s8") do |type, data|
result << data if type == :stdout
end
(ip = /inet addr:(\d+\.\d+\.\d+\.\d+)/.match(result)) && ip[1]
end
config.vm.box = "ubuntu/xenial64"
config.vm.network "public_network", bridge: "ens33"
end
'~/.ssh/config':
Host web
HostName web
User ubuntu
Port 22
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/build/test/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
'trellis/hosts/...':
```ini
[development]
web
````
Edit: The authorized keys were OK, no need to update them.
In the trellis folder of a web app, the ansible-playbook is ran:
$ ansible-playbook server.yml -e env=staging -e 'ansible_ssh_user=ubuntu' -e 'ansible_user=ubuntu'
@strarsis did you ever figure this out? I'm still not sure what Trellis itself could do about it.
@swalkinshaw: Apparently the issue is caused by a line in
development default config that uses the mailhog_install_dir variable at https://github.com/roots/trellis/blob/2773baa313a496227eafbe294ca5b30d484c232a/group_vars/development/mail.yml#L2
```yml
[...]
php_sendmail_path: "{{ mailhog_install_dir }}/mhsendmail"
````
When this line is commented out, the error goes away.
It seems to be an issue with the mailhog role and how its variables are available outside.
@strarsis I believe the problem stems from this entry in one of your hosts files:
[development]
web
Each of the Trellis hosts files lists a [web] group. This group name web should not be nested within (listed under) an [<environment>] group name like [development].
You're running server.yml with env=staging. The implied hosts: web:&staging mean that Ansible will load group_vars corresponding to the web and staging groups. In normal Trellis, there are no group_vars for web. In your example, however, by nesting web within development, I believe you've caused web to inherit the group_vars of development.
You pointed out the problematic definition of php_sendmail_path from group_vars/development/mail.yml. That file's vars would not normally load for -e env=staging, and thus would not cause this issue, but I suppose that file's vars do load in your case because you've nested web under development.
Here is a somewhat related discussion that could shed light on the conflicts that can arise from inadvertently loading group_vars from multiple envs.
I'm not sure what goal led to nesting web under development, but you could propose to discuss unusual customizations at https://discourse.roots.io/. However, given that this appears to be a misconfiguration and not a bug for this GitHub bug tracker, I'm closing the issue.
Most helpful comment
Thanks for the detailed issue.
Unfortunately this is a very weird thing to run into because it shouldn't happen :( I'm not even sure what to say in terms of debugging.
Maybe delete your
vendordir and manually run againansible-galaxy install --force -r requirements.yml -p vendor/rolesagain?Or maybe re-install Ansible? Could try another version like 2.2.0