# Help with blockinfile module running against Proxmox

**URL:** <https://forum.ansible.com/t/help-with-blockinfile-module-running-against-proxmox/26792>\
**Category:** Ansible Project\
**Created:** [February 19, 2018, 8:05pm UTC](https://forum.ansible.com/t/help-with-blockinfile-module-running-against-proxmox/26792 "2018-02-19T20:05:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![saicrazyfire](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@saicrazyfire](https://forum.ansible.com/u/saicrazyfire)\
**Post date:** [February 19, 2018, 8:05pm UTC](https://forum.ansible.com/t/help-with-blockinfile-module-running-against-proxmox/26792/1 "2018-02-19T20:05:43Z")

</div>

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](https://gist.github.com/kvaps/25f730e0ec39dd2e5749fb6b020e71fc))

```auto
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!

---

<div class="post-metadata">

**Author:** ![Troy\_Cauble](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Troy\_Cauble](https://forum.ansible.com/u/Troy_Cauble)\
**Post date:** [March 10, 2018, 7:56pm UTC](https://forum.ansible.com/t/help-with-blockinfile-module-running-against-proxmox/26792/2 "2018-03-10T19:56:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Troy\_Cauble](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Troy\_Cauble](https://forum.ansible.com/u/Troy_Cauble)\
**Post date:** [March 10, 2018, 10:03pm UTC](https://forum.ansible.com/t/help-with-blockinfile-module-running-against-proxmox/26792/3 "2018-03-10T22:03:19Z")

</div>

I found it. /etc/pve is a non-posix compliant filesystem  
[https://pve.proxmox.com/wiki/Proxmox\_Cluster\_File\_System\_(pmxcfs)](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

---

<div class="post-metadata">

**Author:** ![saicrazyfire](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@saicrazyfire](https://forum.ansible.com/u/saicrazyfire)\
**Post date:** [March 11, 2018, 1:06am UTC](https://forum.ansible.com/t/help-with-blockinfile-module-running-against-proxmox/26792/4 "2018-03-11T01:06:13Z")

</div>

Hi Troy,

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

Thanks.

---

<div class="post-metadata">

**Author:** ![Arturo\_Martinez](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Arturo\_Martinez](https://forum.ansible.com/u/Arturo_Martinez)\
**Post date:** [October 16, 2018, 5:22pm UTC](https://forum.ansible.com/t/help-with-blockinfile-module-running-against-proxmox/26792/5 "2018-10-16T17:22:42Z")

</div>

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
