JoeP_108
JoeP_108

Reputation: 53

Issue with adding a "#" sign using Ansible lineinfile module

I am trying to add a # sign in front of a line under /etc/auto.master file as follow

name: Set auto.master step 1

    lineinfile:
     path: /etc/auto.master
     regexp: '^+auto.master'
     line: '^#+auto.master'

However, when I run my playbook, this is what I get

FAILED! => {"changed": false, "module_stderr": "Shared connection to ifmliae1p.bbh.com closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n 5.94-16341-164301267793697/AnsiballZ_lineinfile.py\", line 102, in \r\n _ansiballz_main()\r\n File \"/root/.ansible/tmp/ansible-tmp-1590180565.94-16341-164301267793697/Ansibal\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/root/.ansible/tmp/ansible-tmp-1590180565.94-16341-164301267793697/AnsiballZ_lineinfile.py\", line 40, in invokele.modules.files.lineinfile', init_globals=None, run_name='main', alter_sys=True)\r\n File \"/usr/lib64/python2.7/runpy.py\", line 176, in run_module\r\n fname, loader, pkg_name)\ne 82, in _run_module_code\r\n mod_name, mod_fname, mod_loader, pkg_name)\r\n File \"/usr/lib64/python2.7/runpy.py\", line 72, in _run_code\r\n exec code in run_globals\r\n File _lineinfile_payload.zip/ansible/modules/files/lineinfile.py\", line 573, in \r\n File \"/tmp/ansible_lineinfile_payload_KyHa6O/ansible_lineinfile_payload.zip/ansible/modules/file\"/tmp/ansible_lineinfile_payload_KyHa6O/ansible_lineinfile_payload.zip/ansible/modules/files/lineinfile.py\", line 277, in present\r\n File \"/usr/lib64/python2.7/re.py\", line 190, in r\n File \"/usr/lib64/python2.7/re.py\", line 242, in _compile\r\n raise error, v # invalid expression\r\nsre_constants.error: nothing to repeat\r\n", "msg": "MODULE FAILURE\nSee stdo

I am not sure why it doesn't work. The examples on ansible documentation page seems to work fine.

Upvotes: 2

Views: 339

Answers (2)

CanciuCostin
CanciuCostin

Reputation: 1908

Some possible issues:

  • YAML file wrong indentation
  • unescaped characters

Upvotes: 0

JoeP_108
JoeP_108

Reputation: 53

Apparently, my thinking was going sideways. I thought this line was the issue

line: '^#+auto.master'

But this is the culprit

regexp: '^+auto.master'

The plus sign has to be escaped like so.

  regexp: '^\+auto.master'
  line: '#+auto.master'

Upvotes: 1

Related Questions