Bootstrapping FreeBSD with Ansible 2.0: RAW module does not work anymore?

Hi everyone,

I found some nice articles how to bootstrap FreeBSD machines with
ansible, as they lack a python install by default. Seems
bootstrapping pkg and installing python seems to be enough.

http://lampros.chaidas.com/index.php?controller=post&action=view&id_po
st=56
https://blog.codeways.org/ansible-freebsd/
https://docs.ansible.com/ansible/intro_bsd.html

But when using these kind of commands with ansible 2.0 from a OSX
machine, the command always hangs. When killing the process on the
freebsd machine, I get output similar to this:

ansible -vvv -k -u root XYZ -m raw -a 'env ASSUME_ALWAYS_YES=YES
/usr/sbin/pkg bootstrap -f' SSH password: <XYZ> ESTABLISH
CONNECTION FOR USER: root on PORT 22 TO freebsdmitnat

[...]

<XYZ> EXEC /usr/sbin/pkg bootstrap -f XYZ | FAILED | rc=143 >>
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: Beendet

Apparently the ASSUME_ALWAYS_YES variable does not get set, and thus
the commands ask for confirmation (last two lines of output). When
calling the whole 'env ... -f' command on the freebsd machine, this
works like a charm.

I also tried using root, using a user via sudo or su, but each time
the same behaviour.

Question:
Is this a (known) regression with ansible 2.0 or earlier? All the
articles are a little bit old, maybe this has changed in the meantime?

Anyone having a solution?

Setting ansible_shell_type to csh via host_vars/group_vars/... does
not work.

Thanks in advance,

Johannes

Hi everyone,

as I got no responses, I'll keep the full quote.

No one provisioning FreeBSD machines anymore? Or is this working for
everybody else, but not for me?

Thanks,
Johannes

Hi everyone,

I found some nice articles how to bootstrap FreeBSD machines
with ansible, as they lack a python install by default. Seems
bootstrapping pkg and installing python seems to be enough.

http://lampros.chaidas.com/index.php?controller=post&action=view&id_

po

st=56

I opened issue 15191:
https://github.com/ansible/ansible/issues/15191

Johannes

...and I closed the issue, as I found the problem:

The quoted string has to be quoted again, otherwise the controller's
shell will eat the quotes and the "env ASSUME..." part...

Johannes

I opened issue 15191:
https://github.com/ansible/ansible/issues/15191

...and I closed the issue, as I found the problem:

The quoted string has to be quoted again, otherwise the controller's
shell will eat the quotes and the "env ASSUME..." part...

Once again I eat my words. Seems to become a habit...

The twice-quoted command runs and returns a success message, but
apparently does nothing.

Using the following playbook works:

- hosts: all
  gather_facts: false
  become_method: sudo
  become: yes
  tasks:
    - name: Bootstrapping pkg
      raw: /usr/sbin/pkg -N
      register: pkg
      ignore_errors: True

    - raw: /usr/bin/env ASSUME_ALWAYS_YES=1 /usr/sbin/pkg bootstrap -f
      when: pkg|failed

    - name: install python
      raw: /usr/sbin/pkg install -y python27

So it seems to be some kind of quoting hell. How to quote the argument
for the raw module in a way that everything works?

ansible -m raw -a 'env ASSUME_ALWAYS_YES=YES pkg bootstrap -f' foobar

hangs waiting for the confirmation

ansible -m raw -a "env ASSUME_ALWAYS_YES=YES pkg bootstrap -f" foobar

hangs waiting for the confirmation

ansible -m raw -a '"env ASSUME_ALWAYS_YES=YES pkg bootstrap -f"' foobar

returns with success, but does nothing

ansible -m raw -a "'env ASSUME_ALWAYS_YES=YES pkg bootstrap -f'" foobar

returns with success, but does nothing

ansible -m raw -a "\"env ASSUME_ALWAYS_YES=YES pkg bootstrap -f\"" foobar

returns with success, but does nothing

Regards,
Johannes

Quoting the “=” seems to do the trick at least in my trivial test:

$ ansible -v -m raw -a ‘env -i ABC=blah /usr/bin/printenv’ localhost
Using /etc/ansible/ansible.cfg as config file
localhost | SUCCESS | rc=0 >>
ABC=blah

Interesting, I did not think of the equal sign being the problem. I'll
run some tests against a FreeBSD host and report back...

Johannes

That should be fixed in the latest versions of devel/stable-2.0.

I can confirm that quoting the equal sign works.

Thanks for testing!

Johannes