哪个是在ansible的conf文件中进行配置更改的最佳方法

时间:2021-07-24 20:09:36

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

最初我使用makefile在linux中部署我的应用程序。

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

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

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.

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

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

有时它只是一线改变。有没有更好的方法来编辑ansible中的配置文件?

2 个解决方案

#1


17  

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).

如果它是INI文件,则ini_file模块(http://docs.ansible.com/ini_file_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).

如果您的更改仅限于几行(或前一个),那么您可以查看lineinfile模块(http://docs.ansible.com/lineinfile_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.

但是,如果您需要更改大量设置,那么使用模板(http://docs.ansible.com/template_module.html)或汇编(http://docs.ansible.com/assemble_module)可能更有用。 HTML)。此方法的主要缺点是您可能需要在更新依赖项时检查模板或片段。

#2


0  

Depending on the operating system, you can add files here /etc/php/apache2/conf.d/10-someinifilewithsetting.ini

根据操作系统的不同,您可以在此处添加文件/etc/php/apache2/conf.d/10-someinifilewithsetting.ini

#1


17  

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).

如果它是INI文件,则ini_file模块(http://docs.ansible.com/ini_file_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).

如果您的更改仅限于几行(或前一个),那么您可以查看lineinfile模块(http://docs.ansible.com/lineinfile_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.

但是,如果您需要更改大量设置,那么使用模板(http://docs.ansible.com/template_module.html)或汇编(http://docs.ansible.com/assemble_module)可能更有用。 HTML)。此方法的主要缺点是您可能需要在更新依赖项时检查模板或片段。

#2


0  

Depending on the operating system, you can add files here /etc/php/apache2/conf.d/10-someinifilewithsetting.ini

根据操作系统的不同,您可以在此处添加文件/etc/php/apache2/conf.d/10-someinifilewithsetting.ini