Updateing a password in Grub.conf file using Ansible and Replace

722 views
Skip to first unread message

Alan Harkleroad

unread,
Oct 12, 2016, 3:36:40 PM10/12/16
to Ansible Project
So I wrote a short playbook to update our VMs to update the /boot/grub/grub.conf file to use a new hashed password but the playbook comes back green with no changes. Not sure what I am doing wrong, any help is appreciated.

---
- host: myhosts
  become: true
  become_method: sudo
  tasks:
 
  - name: Update grub.conf file with new passwd hash
    replace:
         dest=/boot/grub/grub.conf
         regexp='password --encrypted currenthash!@#$$$'
         replace='password --encrypted newhash12345667'

Kai Stian Olstad

unread,
Oct 12, 2016, 3:58:25 PM10/12/16
to ansible...@googlegroups.com
Hard to say without knowing how the current hash looks like, but if the
hash contain any regexp special character they need to be escaped.
List of them you'll find here
https://docs.python.org/2/library/re.html#regular-expression-syntax

--
Kai Stian Olstad

Alan Harkleroad

unread,
Oct 13, 2016, 8:04:35 AM10/13/16
to Ansible Project, ansible-pr...@olstad.com
Yes the hash starts with a $ and includes / as well. I dont follow what you mean by escaping them.

Here is an example hash. So how would I have it read that as one character string and swap it with the new hash

 $1$adjkielw$B./Hu9VCs96Zxc3mkVQ35.

Kai Stian Olstad

unread,
Oct 13, 2016, 10:49:35 AM10/13/16
to ansible...@googlegroups.com
On 13. okt. 2016 14:04, Alan Harkleroad wrote:
> Yes the hash starts with a $ and includes / as well. I dont follow what you
> mean by escaping them.

Escaping is also documented here
https://docs.python.org/2/library/re.html#regular-expression-syntax

But it's a back slash (\) in front of a regexp special character so you
can match on them.


> Here is an example hash. So how would I have it read that as one character
> string and swap it with the new hash
>
> $1$adjkielw$B./Hu9VCs96Zxc3mkVQ35.

Here you should escape $ and . like so.

\$1\$adjkielw\$B\./Hu9VCs96Zxc3mkVQ35\.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages