# mode option for lineinfile

**URL:** <https://forum.ansible.com/t/mode-option-for-lineinfile/12344>\
**Category:** Ansible Project\
**Created:** [February 12, 2013, 8:53pm UTC](https://forum.ansible.com/t/mode-option-for-lineinfile/12344 "2013-02-12T20:53:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [February 12, 2013, 8:53pm UTC](https://forum.ansible.com/t/mode-option-for-lineinfile/12344/1 "2013-02-12T20:53:43Z")

</div>

Since lineinfile has a create= option, would it make sense to have a mode= option as well? Otherwise we end up relying on the user's umask...

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [February 12, 2013, 9:24pm UTC](https://forum.ansible.com/t/mode-option-for-lineinfile/12344/2 "2013-02-12T21:24:03Z")

</div>

Yves Dorfsman wrote:

> Since lineinfile has a create= option, would it make sense to have a mode=  
> option as well? Otherwise we end up relying on the user's umask...

I'd be fine with lineinfile using the common file arguments.

Daniel

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [February 12, 2013, 9:40pm UTC](https://forum.ansible.com/t/mode-option-for-lineinfile/12344/3 "2013-02-12T21:40:11Z")

</div>

Would it be changing those attributes for existing files as well, or only when newly created ? Because I don't see the point of integrating the file module usecase also into lineinfile.

Two actions in this case do no harm IMO.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 12, 2013, 10:20pm UTC](https://forum.ansible.com/t/mode-option-for-lineinfile/12344/4 "2013-02-12T22:20:29Z")

</div>

yeah, you're out of date with how this works 🙂

We can easily use that common code on any module that supports a file,  
and we should here.

Any module that produces exactly one file should support all of the  
file options.

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [February 12, 2013, 10:28pm UTC](https://forum.ansible.com/t/mode-option-for-lineinfile/12344/5 "2013-02-12T22:28:01Z")

</div>

> yeah, you're out of date with how this works 🙂

Don't be cruel !

> We can easily use that common code on any module that supports a file,  
> and we should here.
> 
> Any module that produces exactly one file should support all of the  
> file options.

Right, but would it also adapt the file when nothing was created ? I can see it to be confusing when it does, but also when it doesn't. What should people expect ?

PS I added the create= option, so I am to blame for not doing it right the first time 😉

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 12, 2013, 10:34pm UTC](https://forum.ansible.com/t/mode-option-for-lineinfile/12344/6 "2013-02-12T22:34:26Z")

</div>

Sorry 🙂

With options like owner= or mode=, it should always specify that the  
options passed from the file code are set if there is a file there.

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [February 12, 2013, 10:46pm UTC](https://forum.ansible.com/t/mode-option-for-lineinfile/12344/7 "2013-02-12T22:46:29Z")

</div>

IMO if mode= is specified, it should set the mode, regardless of the file being created or already existing.
