Hi!
I am maintaining a set of servers which host some LXD containers on them.
The playbooks to install them go like this: First playbook connects to the
LXD host, installs apps and services including the containers that are
configured for it. A second playbook connects to this host, loops through
its container configuration and adds them to an in-memory inventory group.
These containers are then installed in a second play in this playbook,
using the in-memory inventory group created just before.
This is working beautifully when used via ansible-playbook in push mode.
But with ansible-pull, the add_host group gets defined, but cannot be used
as inventory group later.
See this stripped down demonstration code:
*Playbook (debug.yml):*
---
- name: add container hosts to in-memory inventory
hosts: "{{ target_hosts }}"
remote_user: "{{ user | default('comdok') }}"
tasks:
- debug:
var: groups['containers']
- name: add hosts
add_host:
name: "{{ item.name }}"
ansible_host: "{{ item.ip4 }}"
group: containers
loop: "{{ lxd_containers }}"
no_log: true
- debug:
var: groups['containers']
- name: install LXC containers
hosts:
- containers
remote_user: root
gather_facts: no
...
*Execution:*
$ ansible-pull --accept-host-key --directory /var/lib/ansible/local --full
--only-if-changed --url git@….git --vault-password-file=/etc/ansible/key
--extra-vars "target_hosts=ABC-Host" --inventory
/var/lib/ansible/local/inventory/abc
/var/lib/ansible/local/playbooks/debug.yml -f
Starting Ansible Pull at 2018-11-29 10:48:38
/usr/bin/ansible-pull --accept-host-key --directory /var/lib/ansible/local
--full --only-if-changed --url git@….git
--vault-password-file=/etc/ansible/key --extra-vars target_hosts=ABC-Host
--inventory /var/lib/ansible/local/inventory/abc
/var/lib/ansible/local/playbooks/debug.yml -f
ABC-Host | FAILED! => {
"before": "89954c6b2e486cfae5c8dd34e8e12a000d05ffbb",
"changed": false,
"msg": "Local modifications exist in repository (force=no)."
}
[WARNING]: Unable to update repository. Continuing with (forced) run of
playbook.
PLAY [add container hosts to in-memory inventory]
************************************************************************************************************************************************************************************************************************************************************************************************************************
TASK [Gathering Facts]
***************************************************************************************************************************************************************************************************************************************************************************************************************************************************
ok: [ABC-Host]
TASK [debug]
*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
ok: [ABC-Host] => {
"groups['containers']": "VARIABLE IS NOT DEFINED!"
}
TASK [add hosts]
*********************************************************************************************************************************************************************************************************************************************************************************************************************************************************
changed: [ABC-Host] => (item=None)
changed: [ABC-Host] => (item=None)
changed: [ABC-Host]
TASK [debug]
*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
ok: [ABC-Host] => {
"groups['containers']": [
"ABC-AD",
"ABC-FS"
]
}
PLAY [install LXC containers]
********************************************************************************************************************************************************************************************************************************************************************************************************************************************
skipping: no hosts matched
PLAY RECAP
***************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
ABC-Host : ok=4 changed=1 unreachable=0 failed=0
I assume that ansible-pull is only suitable when adressing the local host?
Or what might be done to re-use the push playbooks in pull mode?
Thanks, Raulo
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/33288a57-7a43-4641-bcdb-ad8db2f39906%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.