Created
February 13, 2015 10:26
-
-
Save junaid18183/bf70a3c1c5584d6aae91 to your computer and use it in GitHub Desktop.
Ansible with Regex to change the lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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