Can't write to a block device with chroot connection

Hi

I am unable to write to a block device /dev/sdb3 mounted as /media/ajaved/PIROOT using Ansible chroot connection. I am using Ubuntu Jammy (22.04) as host OS and my Ansible version is 2.10.8.

Mount point:

/dev/sdb3 on /media/ajaved/PIROOT type ext4 (rw,nosuid,nodev,relatime,errors=remount-ro,uhelper=udisks2)

Please see the error below after running Ansible playbook:

pikvm3 unreachable | msg: Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p "` echo /tmp/.ansible-${USER} `"&& mkdir "` echo /tmp/.ansible-${USER}/ansible-tmp-1714377996.3163822-9271-11225315534968 `" && echo ansible-tmp-1714377996.3163822-9271-11225315534968="` echo /tmp/.ansible-${USER}/ansible-tmp-1714377996.3163822-9271-11225315534968 `" ), exited with result 126

We have set remote_tmp to /tmp/.ansible-${USER} in ansible.cfg file. My SUDO_USER ajaved is also in disk group.
Any help is much appreciated. Thanks

Sorry if this is a stupid question but you are aware that the chroot connection only works locally and that if you are working on a remote server you have to run Ansible on the remote server?

Thanks @chris

I am not working on a remote server. The block device (SD memory card) is attached and mounted locally to my computer where I run Ansible with chroot connection.
Does this answer your question?

1 Like

Thanks for clarifying that, does the /media/ajaved/PIROOT/tmp directory exist?

What does ls -lah /media/ajaved/PIROOT return?

Does it work if you run the playbook as root? I’ve just checked how I use the chroot plugin – on remote servers – and I always run Ansible as root and don’t have remote_tmp set.

Thanks for your reply @chris.

Yes, the /media/ajaved/PIROOT/tmp directory exists and it is empty at the moment.

Here is the ls output.

ls -lah /media/ajaved/PIROOT
total 80K
drwxr-xr-x  17 root root 4.0K Apr 17 18:38 .
drwxr-x---+  6 root root 4.0K Apr 29 18:16 ..
lrwxrwxrwx   1 root root    7 Apr 17 18:38 bin -> usr/bin
drwxr-xr-x   2 root root 4.0K Apr 17 18:38 boot
drwxr-xr-x   2 root root 4.0K Mar  1  2023 dev
drwxr-xr-x  54 root root 4.0K Apr 17 18:38 etc
drwxr-xr-x   3 root root 4.0K Apr 17 18:36 home
lrwxrwxrwx   1 root root    7 Apr 17 18:38 lib -> usr/lib
drwx------   2 root root  16K Apr 17 18:38 lost+found
drwxr-xr-x   2 root root 4.0K Feb  5  2023 mnt
drwxr-xr-x   2 root root 4.0K Apr 17 18:25 opt
dr-xr-xr-x   2 root root 4.0K Mar  1  2023 proc
drwxr-x---   5 root root 4.0K Apr 17 18:36 root
drwxr-xr-x   2 root root 4.0K Mar  1  2023 run
lrwxrwxrwx   1 root root    7 Apr 17 18:38 sbin -> usr/bin
drwxr-xr-x   4 root root 4.0K Mar  1  2023 srv
dr-xr-xr-x   2 root root 4.0K Mar  1  2023 sys
drwxrwxrwt   2 root root 4.0K Apr 17 18:36 tmp
drwxr-xr-x   8 root root 4.0K Apr 17 18:36 usr
drwxr-xr-x  12 root root 4.0K Apr 17 18:25 var

I am running Ansible playbook with sudo, e.g.,

sudo ansible-playbook --limit pikvm3 flash.yml

Sorry I don’t know why you have a error creating the TMPDIR, do you still have an error if you don’t set remote_tmp in ansible.cfg?

Also how have you defined the chroot in the inventory? I use a YAML inventory file, hosts.yml:

all:
  children:
    chroots:
      hosts:
        /chroot:
          ansible_connection: community.general.chroot

And in ansible.cfg:

[defaults]
inventory = hosts.yml

After some debugging, I managed to fix the issue. It was due to QEMU user emulation packages missing in my host OS. So, I basically installed qemu-user and qemu-user-static through APT package manager and Ansible was then able to create TMPDIR using chroot.

Anyways, thanks @chris for all the support.

1 Like