我有一个下面的命令写成ansible,
- set_fact:
user_arg: true
some_arg: "--with some-ver=1.0.0 if {{ user_arg is defined else '' }}"
path: "path/to/file"
- command: "some-command {{ some_arg }} {{ path }}"
请注意,如果定义了--with
参数,我要添加参数名称(some-var=1.0.0
)及其值(user
)。>>
我想使用args
并将其切换为类似的外观>]
- set_fact: user_arg: true some_arg: "--with some-ver=1.0.0 if {{ user_arg is defined else '' }}" path: "path/to/file" - command: "some-command {{ path }}" args: some_arg: "{{ some_arg }}"
但是这会将
some_arg
添加为空值,如果user_arg
未定义,我根本不希望添加它。谁能帮我这个忙。
我有一个如下所示的命令,-an set_fact:user_arg:true some_arg:“ --with some-ver = 1.0.0,如果{{user_arg被定义为else``}}}” path:“ path / to /文件”-命令:“ some -...
您不能使用set_fact
设置变量并在同一set_fact
中使用它。 您必须将它们分解:
- set_fact:
user_arg: true
path: "path/to/file"
- set_fact:
some_arg: "{% if user_arg is defined %}--with some-ver=1.0.0{% endif %}"