如何单独设置ansible模块的单个选项的条件

jak*_*ake 4 conditional jinja2 ansible ansible-playbook

是否可以为ansible模块的单个选项设置条件.

   Using set_fact we can set condition aand use that variable in the ansible module. Alternatively is there any other option to set the condition using if loop in jinja or something like that.
Run Code Online (Sandbox Code Playgroud)

例如:

 - name: Simple PUT operation
   s3:
     bucket: mybucket
     object: /my/desired/key.txt
     src: /usr/local/myfile.txt
     mode: put
Run Code Online (Sandbox Code Playgroud)

我想添加s3_url选项,如果它满足条件sample_var = myapp.If它不满足它不必添加s3_url

   - name: Simple PUT operation
     s3:
       bucket: mybucket
       object: /my/desired/key.txt
       src: /usr/local/myfile.txt
       mode: put 
       s3_url: "s3my url"------if it satisfies sample_var=myapp 
Run Code Online (Sandbox Code Playgroud)

我怎么能在这里使用jinja满足我的条件需要将这个选项添加到ansible模块?

提前致谢..

Kon*_*rov 7

您可能想要阅读有关省略参数的内容:

- name: Simple PUT operation
  s3:
    bucket: mybucket
    object: /my/desired/key.txt
    src: /usr/local/myfile.txt
    mode: put 
    s3_url: "{{ 's3my_url' if sample_var == 'myapp' else omit }}"
Run Code Online (Sandbox Code Playgroud)