首页 » 翻译 » Ansible » 正文

吐槽一下 ansible-playbook ini_file 模块

ansible playbook中有一个ini_file ,主要的作用是用来向一些conf文件写一些内容的,功能确实挺好的,但是我今天要吐槽一个参数项:

 

create

(added in 2.2)
no no
  • yes
  • no
If specified, the file will be created if it does not already exist. By default it will fail if the file is missing.

该参数标明: 2.2 新加入的,好,新加入正常, 但是, 那你这默认值是几个意思?

在以前,我们很可能都是这么写的:

如果 /etc/conf 不存在,在2.2版本之前是可以自动创建的,但是,如果你不小心升级到了2.2,那么抱歉,你的playbook会报错,你需要增加一个项:

我个人认为吧,无论什么理由,ansible在升级版本的时候都应该兼顾之前版本吧? 你这到好,一把玩死, 还得挨个去改,你敢不敢把默认值设为yes?

附录ini_file 使用参数:

parameter required default choices comments
backup

no no
  • yes
  • no
Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
create

(added in 2.2)
no no
  • yes
  • no
If specified, the file will be created if it does not already exist. By default it will fail if the file is missing.
dest

yes
Path to the INI-style file; this file is created if required
group

no
Name of the group that should own the file/directory, as would be fed to chown.
mode

no
Mode the file or directory should be. For those used to /usr/bin/chmod remember that modes are actually octal numbers (like 0644). Leaving off the leading zero will likely have unexpected results. As of version 1.8, the mode may be specified as a symbolic mode (for example, u+rwx or u=rw,g=r,o=r).
no_extra_spaces

(added in 2.1)
no
do not insert spaces before and after ‘=’ symbol
option

no
if set (required for changing a value), this is the name of the option.
May be omitted if adding/removing a whole section.
others

no
all arguments accepted by the file module also work here
owner

no
Name of the user that should own the file/directory, as would be fed to chown.
section

yes
Section name in INI file. This is added if state=present automatically when a single value is being set.
selevel

no s0
Level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the range. _default feature works as for seuser.
serole

no
Role part of SELinux file context, _default feature works as for seuser.
setype

no
Type part of SELinux file context, _default feature works as for seuser.
seuser

no
User part of SELinux file context. Will default to system policy, if applicable. If set to_default, it will use the user portion of the policy if available.
state

no present
  • present
  • absent
If set to absent the option or section will be removed if present instead of created.
unsafe_writes

(added in 2.2)
no
Normally this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, sometimes systems are configured or just broken in ways that prevent this. One example are docker mounted files, they cannot be updated atomically and can only be done in an unsafe manner.
This boolean option allows ansible to fall back to unsafe methods of updating files for those cases in which you do not have any other choice. Be aware that this is subject to race conditions and can lead to data corruption.
value

no
the string value to be associated with an option. May be omitted when removing anoption.

 

 

 

发表评论