# lineinfile in lxc\_container?

**URL:** <https://forum.ansible.com/t/lineinfile-in-lxc-container/36007>\
**Category:** Ansible Project\
**Created:** [November 18, 2021, 12:42pm UTC](https://forum.ansible.com/t/lineinfile-in-lxc-container/36007 "2021-11-18T12:42:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Hector](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@Richard\_Hector](https://forum.ansible.com/u/Richard_Hector)\
**Post date:** [November 18, 2021, 12:42pm UTC](https://forum.ansible.com/t/lineinfile-in-lxc-container/36007/1 "2021-11-18T12:42:51Z")

</div>

Hi all,

I'm using ansible to set up lxc containers, using delegation to the container host.

One task looks like this:

- name: add ansible user to sudoers  
&nbsp;&nbsp;&nbsp;lineinfile:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: "/var/lib/lxc/{{ inventory\_hostname }}/rootfs/etc/sudoers"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: present  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;regexp: "^ansible"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line: 'ansible ALL=(ALL) NOPASSWD: ALL'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;insertafter: '^root'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;validate: '/usr/sbin/visudo -cf %s'  
&nbsp;&nbsp;&nbsp;delegate\_to: "{{ container\_host }}"  
&nbsp;&nbsp;&nbsp;when: start\_container|bool

That has been working fine, until I tried to create a debian bullseye container on a buster host. Unfortunately, the sudoers format has changed slightly, so the buster visudo won't accept the bullseye sudoers file (#includedir is now @includedir).

I tried giving the path to the bullseye visudo, but it's dynamically linked and doesn't work on the buster system.

I could potentially use the lxc\_container module to run a command in the container, but that means I lose lineinfile, and have to do more stuff manually.

Or I could use my temporary workaround, and just assume my sudoers file is ok, and skip validation.

Another option is to add an extra lineinfile task (before that one) to replace @includedir with #includedir, since it's backwards compatible, but that seems too hackish.

Any other suggestions?

Cheers,  
Richard
