Closed lcrownover closed 2 years ago
What is the exact problem tho? I see tasks executed against the hnd1.example.org
host as it comes from the inventory. They fail, but that doesn't seem related to the inventory working?
The problem is that ansible-pull is unable to run when using the foreman.yml inventory. I can use a static inventory with ansible-pull, and I can use the foreman inventory with ansible(-playbook) from my workstation, but when having my remote node use the foreman inventory for its pull, it results in this odd double-cloning behavior.
I'm aware that this might not be the responsibility of theforeman contributors, as it's odd to me that the inventory would be causing this behavior, but I doubt I'll get any traction with the main ansible repo since it only happens using the foreman inventory. I would at least hope that others could reproduce this issue, (or not, in which case I'd be perfectly happy if I have something configured incorrectly).
Do you happen to have a host called localhost
in your Foreman? It's part of the inventory output, so I'd expect it to come from foreman. But then there are two hosts that match the all
in the playbook - localhost and the fqdn notation. And that makes things execute twice. Or so I guess, at least.
I do not. I only have 3 hosts in this foreman instance: hnd1
, n001
, and the foreman server itself. My guess is that localhost
is added to the inventory regardless of where the inventory is queried from, because running the same ansible-inventory -i inventory/foreman.yml --graph
command from my workstation also returns localhost
.
I think I've solved this issue.
When using ansible-pull
, the arguments that take paths are (by default) relative to the path ~/.ansible/pull/hnd1.example.org/myrepo
, unless you specify an absolute path.
For example, this command works:
ansible-pull \
--accept-host-key \
-U ssh://git@git.example.org/myteam/repo.git \
--private-key ~ansible/.ssh/id_rsa \
-u ansible \
-i inventory/foreman.yml \ # <- using the relative path works. path on disk: ~/.ansible/pull/hnd1.example.org/repo/inventory/foreman.yml
--vault-password-file ~ansible/.vault-pass \
playbooks/test/connection_test.yml
While specifying an absolute path causes it to fail:
ansible-pull \
--accept-host-key \
-U ssh://git@git.example.org/myteam/repo.git \
--private-key ~ansible/.ssh/id_rsa \
-u ansible \
-i ~ansible/inventory/foreman.yml \ # <- using an absolute path breaks it, this file is a copy of the file from the repo
--vault-password-file ~ansible/.vault-pass \
ansible/playbooks/test/connection_test.yml
Even if you specify the absolute path to the inventory file that exists in the cached repo directory, -i ~ansible/.ansible/pull/hnd1.example.org/repo/inventory/foreman.yml
, it breaks.
For my purposes, this issue could be consider solved. I'm not sure if it's intended behavior, but I suppose that's not my call to make :)
Thanks for the help!
SUMMARY
When using
ansible-pull
to have nodes configure themselves, I specify myforeman.yml
inventory file for an inventory source. This results in the following error message:My
ansible-pull
command looks like:Running this same command, but using a local
ini
oryml
inventory works fine:Contents of my
foreman.yml
:Which results in a successful graph:
The ultimate goal being: I'm hoping to generate the
hosts
file using Foreman as my CMDB for ansible facts (also usingcallback_foreman
, which is working great!)Also, my
/etc/ansible/ansible.cfg
:ISSUE TYPE
ANSIBLE VERSION
COLLECTION VERSION
KATELLO/FOREMAN VERSION
STEPS TO REPRODUCE
EXPECTED RESULTS
I expect the inventory to process, and for this simplified example, will run the single playbook which just runs
/bin/true
.ACTUAL RESULTS