Ansible Replace Module Kodekloud

 

 


 

 Question:


Solution

In jump_host go to ansible folder and create a playbook.yml

cd ~/ansible/

vi playbook.yml

Change path and replace text according to question

---
- name: ansible-replace-module
hosts: all
become: true
tasks:
- name: Replace a String
replace:
path: /opt/itadmin/blog.txt
regexp: 'xFusionCorp'
replace: "Nautilus"
when: (ansible_user == "tony")

- name: Replace a String
replace:
path: /opt/itadmin/story.txt
regexp: 'Nautilus'
replace: "KodeKloud"
when: (ansible_user == "steve")

- name: Replace a String
replace:
path: /opt/itadmin/media.txt
regexp: 'KodeKloud'
replace: "xFusionCorp Industries"
when: (ansible_user == "banner")


Then run this command to execute

ansible-playbook -i inventory playbook.yml






Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment