From the course: Ansible: From Basics to Guru by Pearson

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Changing file contents

Changing file contents

In this video, we'll talk about options to use Ansible to change file contents. So how does that work? Well, there's a copy of modules involved. We have already seen copy, which can be used to create files with simple contents. There is a replace, which is what you can use for simple replacements. And there is line-in-file. You are really going to like line-in-file. line in file. You can use it to manipulate simple files. You are really going to like line in file. You can use it to manipulate single lines in a text file. Block in file is the alternative. You have already seen it in the previous video. And you can use it to manipulate complete blocks of text. So copy and replace can be used for simple operations. And you use the content argument to the copy module to copy a string into a destination file. You have probably already seen that earlier in another video in this course. So you would use ansible all minus m copy content is hello destination is tmp hello file. To create tmp…

Contents