coxley / ansible_packer

Ansible glue for Archlinux packer
Do What The F*ck You Want To Public License
0 stars 0 forks source link

makepkg_nonroot_user fails when ansible_user not defined #2

Open matthazinski opened 8 years ago

matthazinski commented 8 years ago

I use the same username on most of my machines so I normally don't bother to define per-host user parameters. I encountered this error:

 ____________________________________________________________
< TASK [coxley.packer : AUR | packer-git | download tarball] >
 ------------------------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
  1 ---
                ||----w |
                ||     ||

changed: [10.0.0.229]
 ____________________________________________________________
/ TASK [coxley.packer : AUR | packer-git | upload tarball to \
\ host and extract it]                                       /
 ------------------------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

fatal: [10.0.0.229]: FAILED! => {"failed": true, "msg": "{{ ansible_ssh_user | default(ansible_user) }}: 'ansible_user' is undefined"}
    to retry, use: --limit @main.retry

If I add a host var of ansible_user to my playbook, it works as expected.

coxley commented 8 years ago

Which version of Ansible are you using?

matthazinski commented 8 years ago

Using the latest from Brew.

$ brew info ansible
ansible: stable 2.1.0.0 (bottled), HEAD
Automate deployment, configuration, and upgrading
https://www.ansible.com/
/usr/local/Cellar/ansible/2.1.0.0 (8,896 files, 94.2M) *
  Poured from bottle on 2016-07-26 at 14:20:56
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ansible.rb
==> Dependencies
Build: pkg-config ✔
Required: libyaml ✔, openssl ✔
==> Caveats
Homebrew writes wrapper scripts that set PYTHONPATH in ansible's
execution environment, which is inherited by Python scripts invoked
by ansible. If this causes problems, you can modify your playbooks
to invoke python with -E, which causes python to ignore PYTHONPATH.
coxley commented 8 years ago

Hm, in 2.0+ ansible_user should always be present from what I can find though it may be null.

I'm away most weekend not able to test, but I just added a new filter to finally fall back to remote_user if neither exist.

Alternatively just override makepkg_nonroot_user and you'll be gravy.