Hi all!
Let’s say I have a few hosts (a.local, b.local) with postgresql installed, and I want to add them to bacula system on a backup host (backup.local).
Basically, each database host would have have a file named {{ hostname }}.conf with the following:
-
Extra vars are totally available between plays.
-
Yes, you can get to variables registered for other systems through hostvars:
{{ hostvars[your_hostname_here][variable_here] }}
Thanks! #2 is what I wanted!
I’ve written a small discovery script:
`
#!/bin/sh
for path in “$@”
do
if [ -d “$path” ] || [ -f “$path” ]
then
echo -n “$path”
exit 0
fi
done
exit 1
`
And use it:
`
-
hosts: {{ hostname }}
tasks:
-
name: discover
script: “discover.sh ‘/tmp’ ‘/etc’”
register: pgdir
-
hosts: bacula.local
tasks:
-
debug: msg=“{{ hostvars[hostname][‘pgdir’][‘stdout’] }}”
`
But can I use extra var “hostname” and NOT add it to /etc/ansible/hosts ?
p.s. there probably should be a module to discover remote paths, how do you think?