Help with blockinfile module running against Proxmox

Hi,

I’m trying to create containers in Proxmox via ansible and I’ve gotten most of it working. I’m leveraging LXC containers to host Docker containers (since they’re more lightweight, and easier to create). In order to do so, I need to append a few lines in the configuration of the container.

Let’s say I’m creating a LXC container with ID 100, the following lines needs to be added to /etc/pve/lxc/100.conf (courtesy of https://gist.github.com/kvaps/25f730e0ec39dd2e5749fb6b020e71fc)

lxc.apparmor.profile: unconfined
lxc.cgroup.devices.allow: a
lxc.cap.drop: 
lxc.mount.auto: proc:rw sys:rw

I have the following task in Ansible

  • name: Add configs to LXC for Docker via Proxmox host cfg files
    become: true
    blockinfile:
    path: “/etc/pve/lxc/{{ item }}.conf”
    block: |
    lxc.apparmor.profile: unconfined
    lxc.cgroup.devices.allow: a
    lxc.cap.drop:
    lxc.mount.auto: proc:rw sys:rw
    with_items:
  • 100

but I get this error

TASK [Add configs to LXC for Docker via Proxmox host cfg files] ********************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: OSError: [Errno 1] Operation not permitted: ‘/etc/pve/lxc/.ansible_tmp8TEvvY100.conf’
failed: [192.168.1.6] (item=100) => {“changed”: false, “item”: 100, “msg”: “Failed to replace file: /tmp/tmpuptjyz to /etc/pve/lxc/100.conf: [Errno 1] Operation not permitted: ‘/etc/pve/lxc/.ansible_tmp8TEvvY100.conf’”}

Any help would be appreciated. Thanks!

Did you find a solution? I’m stuck on the same file. Different contents – I’m doing idmaps, but same file.

“msg”: “Failed to replace file: /tmp/tmpTzm6Bh to /etc/pve/lxc/100.conf: [Errno 1] Operation not permitted: ‘/etc/pve/lxc/.ansible_tmpONaD0O100.conf’”

-troy

I found it. /etc/pve is a non-posix compliant filesystem
https://pve.proxmox.com/wiki/Proxmox_Cluster_File_System_(pmxcfs)
and blockinfile (and many other file modules) do their work in /tmp and end with the
equivalent of “cp -a” or “cp -p” which fails to /etc/pve.

Workaround is to copy: to /tmp, do blockinfile: there, “command: cp” back.

-troy

Hi Troy,

No I didn’t get it working before but thank you for posting your solution. I will try it out.

Thanks.

Hello Troy,

Only joined this group to confirm that your solution works, and say thank you so much. I spent a whole weekend trying to find workarounds for this issue, until I found your comment.

All the best,

Arturo