![](/img/trans.png)
[英]how to replace a string on the second line in a text file using a batch file?
[英]How to replace a particular line in a file using ansible?
我想使用 ansible 转到 nignx 配置文件,并将ssl_certificate
行替换为我自己的。 这是nginx.conf
的行
ssl_certificate "/etc/pki/nginx/server.crt";
我只想知道是什么模块以及如何使用它来将证书的路径替换为我想要的。
试试下面
- name: modify
replace:
path=/path/to/nginx.conf
regexp="^(ssl_certificate\s+)[^\n]+$"
replace="ssl_certificate \"/required/file/path/here\";"
要使用ansible替换文件中的特定行,您可以使用lineinfile_module
- name: Replace a localhost entry with our own
lineinfile:
path: nginx.conf
regexp: '^ ssl_certificate "/etc/pki/nginx/server.crt";'
line: ' ssl_certificate "/your/path/server.crt";'
在我的例子中,我得到了这个差异
< ssl_certificate "/etc/pki/nginx/server.crt";
---
> ssl_certificate "/your/path/server.crt";
但请考虑对 NGINX使用ansible 角色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.