<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/lchccieurope/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/lchccieurope">@lchccieurope</a> on 2016-05-20T08:57:50Z</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">pam_limits</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.0.2.0
  config file = 
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.0.2.0
  config file = 
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">none</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Controller: MacOSX 10.11.5<br>
Target: CentOS/7</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">pam_limits misformats comments, first comment has no "#" (and not even space) prefix, third comment is indented twice.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- pam_limits: domain={{item.domain}} limit_type={{item.limit_type}} limit_item={{item.limit_item}} value={{item.value}} comment={{item.comment}}
  with_items:
    - { domain: 'user1', limit_type: 'soft', limit_item: 'nofile', value: '4096', comment: 'Comment 1' }
    - { domain: 'user2', limit_type: 'soft', limit_item: 'nofile', value: '4096', comment: 'Comment 2' }
    - { domain: 'user3', limit_type: 'soft', limit_item: 'nofile', value: '4096', comment: 'Comment 3' }"><pre class="notranslate"><code class="notranslate">- pam_limits: domain={{item.domain}} limit_type={{item.limit_type}} limit_item={{item.limit_item}} value={{item.value}} comment={{item.comment}}
  with_items:
    - { domain: 'user1', limit_type: 'soft', limit_item: 'nofile', value: '4096', comment: 'Comment 1' }
    - { domain: 'user2', limit_type: 'soft', limit_item: 'nofile', value: '4096', comment: 'Comment 2' }
    - { domain: 'user3', limit_type: 'soft', limit_item: 'nofile', value: '4096', comment: 'Comment 3' }
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="user1   soft    nofile  4096    #Comment 1
user2   soft    nofile  4096    #Comment 2
user3   soft    nofile  4096    #Comment 3
# End of file"><pre class="notranslate"><code class="notranslate">user1   soft    nofile  4096    #Comment 1
user2   soft    nofile  4096    #Comment 2
user3   soft    nofile  4096    #Comment 3
# End of file
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# End of file
user1   soft    nofile  4096Comment 1
user2   soft    nofile  4096    #Comment 2
user3   soft    nofile  4096    #       #Comment 3"><pre class="notranslate"><code class="notranslate"># End of file
user1   soft    nofile  4096Comment 1
user2   soft    nofile  4096    #Comment 2
user3   soft    nofile  4096    #       #Comment 3
</code></pre></div>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="155916560" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-extras/issues/2264" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-extras/issues/2264/hovercard" href="https://github.com/ansible/ansible-modules-extras/issues/2264">ansible/ansible-modules-extras#2264</a></p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">pam_limits</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, May 10 2017, 20:04:28) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]
"><pre class="notranslate"><code class="notranslate">ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, May 10 2017, 20:04:28) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]

</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">Default</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Ansible host : Fedora 25<br>
Ansible target : Centos 7.3 (Vagrant centos/7 image)</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">pam_limits breaks limits.conf file if comment is used, making any subsequent pam_limits change fail.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<ul dir="auto">
<li>Run the below playbook.<br>
The behaviour was discovered in Vagrant controlled Virtualbox VM.</li>
</ul>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
- name: Deploy
  hosts: all
  become: true
  become_user: root
  vars:
    user1_limits:
       - { domain: user1, type: soft, name: nofile, value: 1024, comment: User1 }
       - { domain: user1, type: hard, name: nofile, value: 65536, comment: User1 }
       - { domain: user1, type: soft, name: nproc, value: 2047, comment: User1 }
       - { domain: user1, type: hard, name: nproc, value: 16384, comment: User1 }
       - { domain: user1, type: soft, name: stack, value: 10240, comment: User1 }
       - { domain: user1, type: hard, name: stack, value: 32768, comment: User1 }
  tasks:
   - name: set user limits
     pam_limits:
       limit_item: &quot;{{ item.name }}&quot;
       limit_type: &quot;{{ item.type }}&quot;
       value: &quot;{{ item.value }}&quot;
       domain: &quot;{{ item.domain }}&quot;
       comment: &quot;{{ item.comment }}&quot;
     with_items: &quot;{{ user1_limits }}&quot;"><pre class="notranslate">---
- <span class="pl-ent">name</span>: <span class="pl-s">Deploy</span>
  <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">become</span>: <span class="pl-c1">true</span>
  <span class="pl-ent">become_user</span>: <span class="pl-s">root</span>
  <span class="pl-ent">vars</span>:
    <span class="pl-ent">user1_limits</span>:
       - <span class="pl-s">{ domain: user1, type: soft, name: nofile, value: 1024, comment: User1 }</span>
       - <span class="pl-s">{ domain: user1, type: hard, name: nofile, value: 65536, comment: User1 }</span>
       - <span class="pl-s">{ domain: user1, type: soft, name: nproc, value: 2047, comment: User1 }</span>
       - <span class="pl-s">{ domain: user1, type: hard, name: nproc, value: 16384, comment: User1 }</span>
       - <span class="pl-s">{ domain: user1, type: soft, name: stack, value: 10240, comment: User1 }</span>
       - <span class="pl-s">{ domain: user1, type: hard, name: stack, value: 32768, comment: User1 }</span>
  <span class="pl-ent">tasks</span>:
   - <span class="pl-ent">name</span>: <span class="pl-s">set user limits</span>
     <span class="pl-ent">pam_limits</span>:
       <span class="pl-ent">limit_item</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.name }}<span class="pl-pds">"</span></span>
       <span class="pl-ent">limit_type</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.type }}<span class="pl-pds">"</span></span>
       <span class="pl-ent">value</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.value }}<span class="pl-pds">"</span></span>
       <span class="pl-ent">domain</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.domain }}<span class="pl-pds">"</span></span>
       <span class="pl-ent">comment</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.comment }}<span class="pl-pds">"</span></span>
     <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ user1_limits }}<span class="pl-pds">"</span></span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">limits set with comments in limits.conf file :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[...]
user1   soft    nofile  1024 # User1
user1   hard    nofile  65536   # User1
user1   soft    nproc   2047 # User1
user1   hard    nproc   16384 # User1
user1   soft    stack   10240 # User1
user1   hard    stack   32768 # User1"><pre class="notranslate"><code class="notranslate">[...]
user1   soft    nofile  1024 # User1
user1   hard    nofile  65536   # User1
user1   soft    nproc   2047 # User1
user1   hard    nproc   16384 # User1
user1   soft    stack   10240 # User1
user1   hard    stack   32768 # User1
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [Deploy] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [default]

TASK [set user limits] *******************************************************
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'nofile', u'value': 1024})
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'nofile', u'value': 65536})
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'nproc', u'value': 2047})
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'nproc', u'value': 16384})
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'stack', u'value': 10240})
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'stack', u'value': 32768})

PLAY RECAP *********************************************************************
default                    : ok=2    changed=1    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">PLAY [Deploy] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [default]

TASK [set user limits] *******************************************************
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'nofile', u'value': 1024})
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'nofile', u'value': 65536})
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'nproc', u'value': 2047})
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'nproc', u'value': 16384})
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'stack', u'value': 10240})
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'stack', u'value': 32768})

PLAY RECAP *********************************************************************
default                    : ok=2    changed=1    unreachable=0    failed=0
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Limits are not set at all, apart from first limit in first playbook run.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="user1   soft    nofile  1024User1"><pre class="notranslate"><code class="notranslate">user1   soft    nofile  1024User1
</code></pre></div>
<p dir="auto">If comment contains "#" itself, behaviour changes to :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="user1   hard    nofile  65536   ## User1
user1   soft    nproc   2047    #       ## User1
user1   hard    nproc   16384   #       #       ## User1
user1   soft    stack   10240   #       #       #       ## User1
user1   hard    stack   32768   #       #       #       #       ## User1"><pre class="notranslate"><code class="notranslate">user1   hard    nofile  65536   ## User1
user1   soft    nproc   2047    #       ## User1
user1   hard    nproc   16384   #       #       ## User1
user1   soft    stack   10240   #       #       #       ## User1
user1   hard    stack   32768   #       #       #       #       ## User1
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [Deploy] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [default]

TASK [set user limits] *******************************************************
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'nofile', u'value': 1024})
failed: [default] (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'nofile', u'value': 65536}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;comment&quot;: &quot;User1&quot;, &quot;domain&quot;: &quot;user1&quot;, &quot;name&quot;: &quot;nofile&quot;, &quot;type&quot;: &quot;hard&quot;, &quot;value&quot;: 65536}, &quot;msg&quot;: &quot;Invalid configuration of '/etc/security/limits.conf'. Current value of nofile is unsupported.&quot;}
failed: [default] (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'nproc', u'value': 2047}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;comment&quot;: &quot;User1&quot;, &quot;domain&quot;: &quot;user1&quot;, &quot;name&quot;: &quot;nproc&quot;, &quot;type&quot;: &quot;soft&quot;, &quot;value&quot;: 2047}, &quot;msg&quot;: &quot;Invalid configuration of '/etc/security/limits.conf'. Current value of nofile is unsupported.&quot;}
failed: [default] (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'nproc', u'value': 16384}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;comment&quot;: &quot;User1&quot;, &quot;domain&quot;: &quot;user1&quot;, &quot;name&quot;: &quot;nproc&quot;, &quot;type&quot;: &quot;hard&quot;, &quot;value&quot;: 16384}, &quot;msg&quot;: &quot;Invalid configuration of '/etc/security/limits.conf'. Current value of nofile is unsupported.&quot;}
failed: [default] (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'stack', u'value': 10240}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;comment&quot;: &quot;User1&quot;, &quot;domain&quot;: &quot;user1&quot;, &quot;name&quot;: &quot;stack&quot;, &quot;type&quot;: &quot;soft&quot;, &quot;value&quot;: 10240}, &quot;msg&quot;: &quot;Invalid configuration of '/etc/security/limits.conf'. Current value of nofile is unsupported.&quot;}
failed: [default] (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'stack', u'value': 32768}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;comment&quot;: &quot;User1&quot;, &quot;domain&quot;: &quot;user1&quot;, &quot;name&quot;: &quot;stack&quot;, &quot;type&quot;: &quot;hard&quot;, &quot;value&quot;: 32768}, &quot;msg&quot;: &quot;Invalid configuration of '/etc/security/limits.conf'. Current value of nofile is unsupported.&quot;}

PLAY RECAP *********************************************************************
default                    : ok=1    changed=0    unreachable=0    failed=1"><pre class="notranslate"><code class="notranslate">PLAY [Deploy] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [default]

TASK [set user limits] *******************************************************
changed: [default] =&gt; (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'nofile', u'value': 1024})
failed: [default] (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'nofile', u'value': 65536}) =&gt; {"failed": true, "item": {"comment": "User1", "domain": "user1", "name": "nofile", "type": "hard", "value": 65536}, "msg": "Invalid configuration of '/etc/security/limits.conf'. Current value of nofile is unsupported."}
failed: [default] (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'nproc', u'value': 2047}) =&gt; {"failed": true, "item": {"comment": "User1", "domain": "user1", "name": "nproc", "type": "soft", "value": 2047}, "msg": "Invalid configuration of '/etc/security/limits.conf'. Current value of nofile is unsupported."}
failed: [default] (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'nproc', u'value': 16384}) =&gt; {"failed": true, "item": {"comment": "User1", "domain": "user1", "name": "nproc", "type": "hard", "value": 16384}, "msg": "Invalid configuration of '/etc/security/limits.conf'. Current value of nofile is unsupported."}
failed: [default] (item={u'comment': u'User1', u'domain': u'user1', u'type': u'soft', u'name': u'stack', u'value': 10240}) =&gt; {"failed": true, "item": {"comment": "User1", "domain": "user1", "name": "stack", "type": "soft", "value": 10240}, "msg": "Invalid configuration of '/etc/security/limits.conf'. Current value of nofile is unsupported."}
failed: [default] (item={u'comment': u'User1', u'domain': u'user1', u'type': u'hard', u'name': u'stack', u'value': 32768}) =&gt; {"failed": true, "item": {"comment": "User1", "domain": "user1", "name": "stack", "type": "hard", "value": 32768}, "msg": "Invalid configuration of '/etc/security/limits.conf'. Current value of nofile is unsupported."}

PLAY RECAP *********************************************************************
default                    : ok=1    changed=0    unreachable=0    failed=1
</code></pre></div>