lineinfile append to line?

118 views
Skip to first unread message

leam hall

unread,
Nov 16, 2017, 4:42:19 PM11/16/17
to Ansible Project
Trying to edit grub.conf and add a phrase to the kernel lines.

Sample stanza:

title CentOS (2.6.32-696.13.2.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-696.13.2.el6.x86_64 ro root=/dev/mapper/vg_root-lv_root rd_NO_LUKS rd_LVM_LV=vg_root/lv_root LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 console=ttyS0,115200n8 rd_LVM_LV=vg_root/lv_swap KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet rd_NO_DM
    initrd /initramfs-2.6.32-696.13.2.el6.x86_64.img


Ansible playbook stanza that's not working:

- name: edit_grub_conf
   lineinfile:
     path: "/tmp/grub.conf"
     regexp: "^kernel(.*)?"
     line: 'kernel\1 transparent_hugepage=never'
     state: present
     backrefs: true
     mode: 0666

Error reported:

TASK [edit_grub_conf] **********************************************************
fatal: [leviticus]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to leviticus closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_PUtMtv/ansible_module_lineinfile.py\", line 470, in <module>\r\n main()\r\n File \"/tmp/ansible_PUtMtv/ansible_module_lineinfile.py\", line 462, in main\r\n ins_aft, ins_bef, create, backup, backrefs)\r\n File \"/tmp/ansible_PUtMtv/ansible_module_lineinfile.py\", line 261, in present\r\n bre_m = re.compile(to_bytes(regexp, errors='surrogate_or_strict'))\r\n File \"/usr/lib64/python2.6/re.py\", line 190, in compile\r\n return _compile(pattern, flags)\r\n File \"/usr/lib64/python2.6/re.py\", line 245, in _compile\r\n raise error, v # invalid expression\r\nsre_constants.error: nothing to repeat\r\n", "msg": "MODULE FAILURE", "rc": 0}


What am I missing?

Thanks!

Leam

leam hall

unread,
Nov 17, 2017, 5:22:26 AM11/17/17
to Ansible Project

Interesting. I read http://www.mydailytutorials.com/ansible-lineinfile-module-examples/    and used the example as a starting point. Found out lineinfile only works on one line in the file, not all of them. And just the last one.
 
Reply all
Reply to author
Forward
0 new messages