在 ansible 中对 conf 文件进行配置更改的最佳方法是什么 [英] Which is the best way to make config changes in conf files in ansible

查看:22
本文介绍了在 ansible 中对 conf 文件进行配置更改的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初我使用 makefilelinux 中部署我的应用程序.

Initially I used a makefile to deploy my application in linux.

我有各种 sed 命令来替换 PHP 上传文件大小、帖子大小、日志文件位置等变量.

I had various sed commands to replace variables like the PHP upload file size, post size, log file location etc.

现在我正在转向 ansible.我知道我可以复制这些文件,但是如何更改 conf 文件?就像我只想更改 upload_filesize = 50M 参数一样.我不想复制整个 conf 文件,然后用我的文件替换.

Now I am shifting to ansible. I know I can copy the files, but how can I make changes to the conf files? Like if i just want to change the upload_filesize = 50M parameter. I don't want to make copies of the whole conf file and then replace with my file.

有时只是一行更改.有没有更好的方法在 ansible 中编辑配置文件?

Sometimes it’s only a one-line change. Is there any better way to edit the config files in ansible?

推荐答案

如果是INI文件,那么ini_file模块(http://docs.ansible.com/ini_file_module.html).

If it's an INI file, then your specific requirements can be probably met by ini_file module (http://docs.ansible.com/ini_file_module.html).

如果您的更改仅限于几行(或前夕),那么您可能可以查看 lineinfile 模块(http://docs.ansible.com/lineinfile_module.html).

If your change is limited just few lines (or eve one), then you can probably look at lineinfile module (http://docs.ansible.com/lineinfile_module.html).

然而,如果您需要更改大量设置,那么使用 template (http://docs.ansible.com/template_module.html) 或 assemble (http://docs.ansible.com/assemble_module.html).这种方法的主要缺点是您可能需要在更新依赖项时检查模板或片段.

Should you however need to change large number of settings, then it may be more beneficial to use template (http://docs.ansible.com/template_module.html) or assemble (http://docs.ansible.com/assemble_module.html). The main disadvantage of this approach is that you may need to review your template or fragments when updating your dependency.

这篇关于在 ansible 中对 conf 文件进行配置更改的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆