0

I wanted to search and replace "GATEWAY=192.168.0.253" in ansible plabook. I've below code but string is not getting replaced. I am not good with Any help will be appreciated to match the string end of the line.

 tasks:
    - name: "Homenet GateWay Change"
      replace:
        dest: /opt/ifcfg-br0
        regexp: '^(GATEWAY=)\s*$'
        replace: 'GATEWAY=192.168.0.1'
        backup: yes
      when: HOMENET
    - name: "Hoemnet DNS Change"
      replace:
        dest: /opt/ifcfg-br0
        regexp: '^(DNS1=)\s*$'
        replace: 'DNS1=192.168.0.1'
        backup: yes
      when: HOMENET
    - service: name=network state=restarted 
2

1 Answer 1

1

If you are looking for any IP address, you can use this regex:

GATEWAY=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}

Or if you are not looking for valid IP's you can also just use this regex:

GATEWAY=[0-9\.]+

And replace it with

GATEWAY=192.168.0.1

Here is a running example:

var text = "This is a GATEWAY=192.168.0.3 and this is also a GATEWAY=192.168.0.8";
var regex = /GATEWAY=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g
var replacement = "GATEWAY=192.168.0.1";

var result = text.replace(regex, replacement);
console.log(result);

2
  • Thank you for quick response Commented Jan 22, 2017 at 2:21
  • Does this help you? You can upvote and accept (✔ on the left side) the question if you like to.
    – ssc-hrep3
    Commented Jan 22, 2017 at 2:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.