Skip to content

Instantly share code, notes, and snippets.

@junaid18183
Created February 13, 2015 10:26
Show Gist options
  • Save junaid18183/bf70a3c1c5584d6aae91 to your computer and use it in GitHub Desktop.
Save junaid18183/bf70a3c1c5584d6aae91 to your computer and use it in GitHub Desktop.
Ansible with Regex to change the lines
---
- name: Deploy dbserver
hosts: all
user: root
pre_tasks:
vars :
- Dest : /etc/ansible/facts.d/sojourner.fact
pre_tasks:
- name : Check if {{Dest}} exist's
stat: path={{ Dest }}
register: st
- replace : dest={{ Dest }} regexp='Product=((?!{{Product}})[\w\s]+)\n' replace="Product={{Product}} \1\n"
when: st.stat.exists is defined and st.stat.exists==True
- replace : dest={{ Dest }} regexp='Role=((?!{{Role}})[\w\s]+)\n' replace="Role={{Role}} \1\n"
when: st.stat.exists is defined and st.stat.exists==True
- lineinfile : dest={{ Dest }} regexp='\[setup\][\n]Product=[\w\s]*[\n]Role=[\w\s]+' line='[setup]\nProduct={{Product}}\nRole={{Role}}' create=yes mode=644
when: st.stat.exists is defined and st.stat.exists==False
handlers:
- name: re-read facts
setup: filter=ansible_local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment