这是在ans文件中更改conf文件的最佳方法 [英] Which is the best way to make config changes in conf files in ansible
问题描述
最初,我使用makefile
将应用程序部署在linux
中.
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?
推荐答案
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.
这篇关于这是在ans文件中更改conf文件的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!