Co-authored-by: Matt Clay <matt@mystile.com>
Co-authored-by: Matt Davis <mrd@redhat.com>
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
This addresses a bug in ansible-pull where running ansible-pull
with an existing inventory causes the ansible job that does
the SCM checkout to run twice - once for localhost and once
for the fully qualified hostname.
This can cause a race condition, and usually results in one
of the ansible checkouts failing because one of the scm checkouts
has its references updated underneath it. Although the SCM checkout
actually succeeds, ansible fails with non-zero exit status, and
so ansible-pull does not continue.
Now that localhost is implicit for ansible runs, the ansible
scm checkout can be done using just localhost as a target.
Thi permit to simplify the command line to use by using
a sensible default, and so reduce the number of incorrect
possible choices and setup needed. Among potential
incorrect choices is using a fixed directory in /tmp, which
could be problematic with a setup whose access is not
properly restricted.
For a small network ( home, small company ), having to put the FQDN
in each file is a bit tedious, so this patch also add the shorthostname
as a 3rd default if the fqdn is not found.
This extends ansible-pull so that it can support using other
source_control modules for checking out a playbook repository
(issue #3372). This will check to see if the module exists before
it attempts to do the checkout and will exit if the module is not found.
It requires that the module used to check out the repository support the
parameters 'name' and 'version'. The option -C, --checkout is now
optional and defaults to the module's default behavior for selecting a
branch, tag, or commit value. For git, this continues to be HEAD.
Other changes include:
* Remove git from help and use generic term(s) where needed.
* Use SortedOptParser from ansible.utils
* More abstraction of common options used between ansible and
ansible-playbook.
* Moved the --list-hosts option that is common to both `ansible` and
`ansible-playbook` into utils/__init__.py (corrects a FIXME)
* Wrote new help text for the --list-hosts option that makes sense
for both of the commands that it applies to
* Changed the usage argument in `ansible-playbook` so that it is
setup in the base_parser method the same way that it is in
the `ansible` executable
* Updated the help text for several options to correct typos,
clarify meaning, improve readability, or fix grammatical errors.
In the case of `ansible-pull`, I changed the help text so that
it adheres to the same standards as the other executables.
Add option to specify inventory. No default is defined since
ansible-playbook already does this and it allows an ansible.cfg in the
git repository to take precedence.
Overall, this should help ansible-pull work with less setup in advance,
which should be helpful in kickstart scenarios. Much of this was
discussed in issue #2464.
A first stab at a pull-based model for ansible. This does two things:
1. Invoke the git module via Runner to set up a git repository on the
localhost. It sets up Runner to use transport='local' and forces
the inventory to just 'localhost'.
2. Run any playbooks provided. By default, this wants to run the
playbook local.yml. This also sets transport='local' and sets
the host_list to a list: localhost, fqdn, and hostname.
The reason for setting the host_list and not using override_hosts is
because there may be plays in the playbook that are not meant for a
specific host. That is, if the git repository is for the entire site
and not host-specific, you don't want to override hosts and apply all
plays to any given host. This has the downside of potentially running a
play three times if the play is defined for 'hosts: all'.