I am new to ansible.
Is there a simple way to replace the line starting with option domain-name-servers
in /etc/dhcp/interface-br0.conf
with mo
You can use Replace Module. Please refer to http://docs.ansible.com/ansible/latest/modules/replace_module.html.
#example
vim httpd-replace-hostname.yml
---
- hosts:
tasks:
- name: hostname was used instead of path.
replace:
path: /etc/hosts
regexp: '(\s+)old\.name\.com(\s+.*)?$'
replace: '\new.name.com\2'
backup: yes
Run
ansible-playbook httpd-replace-hostname.yml
You can check out the result successfully as below.
PLAY [Your hosts] ***************************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************************
ok: [hostname.name.com]
TASK [hostname was used instead of path.] ***************************************************************************************************************************************
ok: [hostname.name.com]
TASK [Replace after the expression till the end of the file] ********************************************************************************************************************
changed: [hostname.name.com]
PLAY RECAP **********************************************************************************************************************************************************************
hostname.name.com : ok=3 changed=1 unreachable=0 failed=0