Is that possible to set conditions for a single option of the ansible module.
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.
E.g:
- name: Simple PUT operation
s3:
bucket: mybucket
object: /my/desired/key.txt
src: /usr/local/myfile.txt
mode: put
I want to add s3_url option if it satifies the condition sample_var= myapp.If it doesnot satify it wont have to add 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
How can i use jinja here when it satisfies my condition it needs to add this option to the ansible module?
Thanks in advance..
To implement conditions in Ansible, we use the when keyword. The keyword takes Boolean expressions based on a value or a variable from previous tasks or facts gathered from the remote hosts.
Use this command to run a playbook: $ ansible-playbook <playbook. yml> Use this command to check the playbook for syntax errors: $ ansible-playbook <playbook. yml> --syntax-check.
In diff mode, Ansible provides before-and-after comparisons. Modules that support diff mode display detailed information. You can combine check mode and diff mode for detailed validation of your playbook or role.
You may want to read about omitting parameters:
- 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 }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With