Error in lineinfile module

649 views
Skip to first unread message

Kavin Kankeshwar

unread,
Mar 13, 2013, 2:49:38 PM3/13/13
to ansible...@googlegroups.com
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 <module>
    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 <module>
    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

James Marcus

unread,
Mar 13, 2013, 4:39:30 PM3/13/13
to ansible...@googlegroups.com
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


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Kavin Kankeshwar

unread,
Mar 13, 2013, 5:47:37 PM3/13/13
to ansible...@googlegroups.com
Thanks that Works !!! Figured out by issues was the regex was wrong should have done  "\*" to escape * and match it.

Regards,
--
Kavin Kankeshwar

Marco Crivellaro

unread,
May 22, 2015, 11:57:50 AM5/22/15
to ansible...@googlegroups.com, ka...@aerospike.com
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"





Reply all
Reply to author
Forward
0 new messages