Error in lineinfile module

I have the latest version of Ansible and I keep getting the following stack trace in lineinfile module, Also i have copied my playbook below.

Stacktrace:

fatal: [d7] => failed to parse: Traceback (most recent call last):
File “/root/.ansible/tmp/ansible-1363200342.59-196252252580469/lineinfile”, line 1031, in
main()
File “/root/.ansible/tmp/ansible-1363200342.59-196252252580469/lineinfile”, line 270, in main
params[‘insertafter’], params[‘insertbefore’], create, backup)
File “/root/.ansible/tmp/ansible-1363200342.59-196252252580469/lineinfile”, line 144, in present
mre = re.compile(regexp)
File “/usr/lib64/python2.6/re.py”, line 190, in compile
return _compile(pattern, flags)
File “/usr/lib64/python2.6/re.py”, line 245, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat

fatal: [d8] => failed to parse: Traceback (most recent call last):
File “/root/.ansible/tmp/ansible-1363200342.59-246123346146030/lineinfile”, line 1031, in
main()
File “/root/.ansible/tmp/ansible-1363200342.59-246123346146030/lineinfile”, line 270, in main
params[‘insertafter’], params[‘insertbefore’], create, backup)
File “/root/.ansible/tmp/ansible-1363200342.59-246123346146030/lineinfile”, line 144, in present
mre = re.compile(regexp)
File “/usr/lib64/python2.6/re.py”, line 190, in compile
return _compile(pattern, flags)
File “/usr/lib64/python2.6/re.py”, line 245, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat

FATAL: all hosts have already failed – aborting

Playbook:

  • name: Add Hardlimit
    lineinfile: dest=/etc/security/limits.conf regexp=‘* hard nofile 100000’ line=‘* hard nofile 100000’ state=present
    only_if: ‘$is_centos’
    tags:

  • addlimits

  • name: Add Hardlimit
    lineinfile: dest=/etc/security/limits.conf regexp=‘* soft nofile 100000’ line=‘* soft nofile 100000’ state=present
    only_if: ‘$is_centos’
    tags:

  • addlimits

  • name: Add Hardlimit
    lineinfile: dest=/etc/security/limits.conf regexp=‘root hard nofile 100000’ line=‘* hard nofile 100000’ state=present
    only_if: ‘$is_centos’
    tags:

  • addlimits

  • name: Add Hardlimit
    lineinfile: dest=/etc/security/limits.conf regexp=‘root soft nofile 100000’ line=‘* soft nofile 100000’ state=present
    only_if: ‘$is_centos’
    tags:

  • addlimits

Regards,–
Kavin Kankeshwar

Hi Kavin,
Sent this to you privately but I think this has been working fine for us:

  • name: Add the hard limits configuraiton for CitrusLeaf
    action: lineinfile dest=/etc/security/limits.conf create=no insertafter=EOF regexp=“hard nofile 100000” line=“* hard nofile 100000” state=present
    tags:

  • LimitsConf

  • name: Add the soft limits configuraiton for CitrusLeaf
    action: lineinfile dest=/etc/security/limits.conf create=no insertafter=EOF regexp=“soft nofile 100000” line=“* soft nofile 100000” state=present
    tags:

  • LimitsConf

Thanks that Works !!! Figured out by issues was the regex was wrong should have done “*” to escape * and match it.

Regards,–
Kavin Kankeshwar

I’d suggest a different approach by using a regexp which will let you alter the exiting limit in the future:

  • name: sets nofile hard limits
    lineinfile: >
    dest=/etc/security/limits.conf
    line=“* hard nofile 65536”
    regexp=“^\*\ +hard\ +nofile\ +[0-9]+$”
    state=“present”