I am currently learning Ansible. This is due to the fact that I realized I had to have a way to simultaneously configure many servers: I was up to using 6 (six) virtual centOS servers to learn glusterfs and manually coniguring each one was geting troublesome. Anyhow I think I am a week into this already.
Todays lesson is: How to replace variables with comments on top. This is a personal favorite style of mine, specifically in the form:
# Previous value was VAR=value changed 20170504
VAR=newvalue
I use this variable A LOT, in fact on all of my configuration changes whenever I can.
Here are two examples from my personal tests.
One way is to simply use newlines:
This task:
====================================================
- name: positional backrefs embedded newline hacks
lineinfile:
dest: /tmp/testconfig.cfg
regexp: '^(TESTCONFIGVAR9)=(.*)'
line: '# \1 modified {{mod_timestamp_long}}
\n# \1 = (old value was) \2
\n\1=newvalue'
backrefs: yes
state: present
====================================================
Produces this output:
====================================================
# TESTCONFIGVAR9 modified 20170504T001157
# TESTCONFIGVAR9 = (old value was) test
TESTCONFIGVAR9=newvalue
====================================================
Another way is to split up the task:
These tasks:
====================================================
- name: another attempt at custom mod notes, step 1
lineinfile:
dest: /tmp/testconfig.cfg
regexp: '^(TESTCONFIGVAR6=.*)'
line: '# OLD VALUE: \1 {{ mod_timestamp_long }}'
backrefs: yes
- name: another attempt at custom mod notes, step 2
lineinfile:
dest: /tmp/testconfig.cfg
insertafter: '# OLD VALUE: '
line: 'TESTCONFIGVAR6=blahblahblah'
====================================================
Result in this output:
====================================================
# OLD VALUE: TESTCONFIGVAR6=test 20170504T001157
TESTCONFIGVAR6=blahblahblah
====================================================
If anybody is reading this, I am open to suggestions (since I am still learning this at the moment).
JondZ Thu May 4 00:16:35 EDT 2017
Subscribe to:
Posts (Atom)
Creating ipip tunnels in RedHat 8 that is compatible with LVS/TUN. Every few seasons I built a virtual LVS (Linux Virtual Server) mock up ju...
-
Occasionally we are troubled by failure alerts; since I have installed the check_crm nagios monitor plugin the alert seems more 'sensiti...
-
This is how to set up a dummy interface on RedHat/CentOS 8.x. I cannot make the old style of init scripts in /etc/sysconfig/network-scripts...
-
While testing pacemaker clustering with iscsi (on redhat 8 beta) I came upon this error: Pending Fencing Actions: * unfencing of rh-8beta...