Right. So FreeBSD does not come with Python preinstalled. Let that sink in. You have got Ansible on your control machine, ready to automate the world, and the target system is just sitting there like a bloke at a pub who does not speak the language. Ansible needs Python. FreeBSD does not have Python. Nobody told either of them about this arrangement beforehand.
Now, you would think, "Fine, I will just use
pkg to install Python and get on
with my life." And you would be wrong. Because
the first time you invoke pkg on a
fresh FreeBSD box, it pulls this little stunt:
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]:
A yes-or-no prompt. On a system you are trying
to manage programmatically. Brilliant.
And here is the best part: this happens even if
you pass the -y flag. You are
standing there telling pkg, "Yes,
mate, I want this, I explicitly said yes," and
pkg is ignoring you like a bouncer
who has already decided you are not getting in.
Ansible will just hang there on your control
machine, waiting forever for a prompt that no
human will ever answer.
The fix is absurdly simple once you know it
exists, which of course you do not until you
have wasted twenty minutes staring at a frozen
terminal wondering if the internet is broken.
You set the ASSUME_ALWAYS_YES
environment variable to yes and
use the raw module because,
remember, there is no Python yet, so none of
Ansible's nice modules work:
$ ansible freebsd -m raw -a "setenv ASSUME_ALWAYS_YES yes; pkg install -y python27"
That is it. That is the whole trick. An
environment variable. Not a secret flag, not a
kernel patch, not a blood sacrifice to the BSD
daemon. Just an environment variable that tells
pkg to stop asking stupid questions
and get on with installing things like a proper
package manager.
-
FreeBSD has no Python out of the box, so use
Ansible's
rawmodule to bootstrap it -
The
-yflag does not suppress the initialpkgbootstrap prompt — you needASSUME_ALWAYS_YES=yes - Once Python is installed, normal Ansible modules work and you can stop living like an animal