for what it's worth i figured out a solution to this using namespaces. i'll leave the full script upto the reader, but maybe this will help someone later
unshare --uts=<file> chroot <rootdir> /bin/bash once in the new namespace, you can change the hostname and it does not affect the base system, which i verified with - hostname outside the chroot hosta - inside the chroot ansible -m setup localhost | egrep "hostname|nodename|fqdn" ansible_hostname = "hostb" ansible_fqdn = "hostb" ansible_nodename = "hostb" On Thu, Mar 14, 2024 at 1:35 PM Michael DiDomenico <[email protected]> wrote: > i have a series of playbooks that use ansible_hostname to determine > whether tasks should run. on a host these work fine as one would expect, > but when running ansible inside a chroot environment with /proc,sys,dev > mounted. ansible pulls the hostname from the host outside of the chroot > into ansible_hostname,ansible_fqdn,ansible_nodename variables > > is there a reliable way to tell ansible, this is what the hostname name > regardless outside factors? > > i tried settings facts to override the three variables or tricking it > through the inventory, but 'ansible -m setup localhost' inside the chroot > always seems to grab the hostname from outside the chroot > > i'm likely doing something wrong, but i'm not sure what > > thanks > > > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CABOsP2Mz%3DYf9sGGcM%2BJLE6RHfwSMKb8WWq8FmdFx5by9y1NEfw%40mail.gmail.com.
