Ansible Replace Module error


I can’t find what is wrong in this task and I’m getting stuck.

Once apply the playbook.yml the content of the file in stapp03 looks like correct to me.

However whet I check the task I get this error:

  • it seems like values are not replaced in ‘/opt/security/media.txt’ file on stapp03

The values to replace are copy from the instructions and the replace is done after apply the playbook.

This is the content of the file with (edit a typo) the change replaced and before it:

Thank you

Hello Roberto,
this seems like what’s happening with me, I can’t ssh to any of the datacenter machines stapp01, stapp02, stapp03, stbkp01, stmail01, or any other.

1 Like

I pass the task finally.

I think I found a bug in this task so I explain what I’ve found in case it is useful to fix it.

I believe that the content of the file media.txt in stapp03 is not the same when task start and when the checks are done.

  1. Using Ansible replace module replace string KodeKloud to xFusionCorp Industries in that file.

To resolve this part my code was

      path: /opt/sysops/media.txt
      regexp: '^(.+)KodeKloud(.+)$'
      replace: '\1xFusionCorp Industries\2'

And that worked as it can be seen in my initial post capture. It works always, every ansible playbook run. I’ve try the task so many times.

However after checks fails when I read the file I saw:
Welcome to KodeKloud
instead the content when the task starts:
Welcome to KodeKloud !

Changing regexp from '^(.+)KodeKloud(.+)$' to 'KodeKloud' checks has been passed but I think the content in the file should be the same to have the same behavior in both cases: running the task solution or running checks.

I hope I can be of help.