Hello everyone are you working on Ansible Automations?!!
This is post is for you to help, In this post you will find more interesting variable usages and their operations with different options such as comparison operators and membership operators.
Comparison operators
This is an example for Comparison operators
Membership operators
--- # Filename: test_compare.yml - name: Comparison Operator example hosts: localhost gather_facts: false vars: a: "Vybhava" b: "Technologies" n: 100 m: 500 tasks: - debug: msg: - "This will compare numbers {{n}} and {{m}} " - " n == m: {{ n == m }}" - " n != m: {{ n != m }}" - " n > m: {{ n > m }}" - " n >= m: {{ n >= m }}" - " n <= m: {{ n <= m }}" - " n < m: {{ n < m }}" - "Compare Strings : a {{a}} and b {{b}}" - " a == b: {{ a == b }}" - " a != b: {{ a != b }}" - " a > b: {{ a > b }}" - " a >= b: {{ a >= b }}" - " a <= b: {{ a <= b }}" - " a < b: {{ a < b }}" - " not a == b: {{ not a == b }}"
Testing
ansible-playbook test_compare.yml Execution Image
Ansible boolean operators their execution outputs |
--- - name: membership operators hosts: localhost gather_facts: no vars: i: 5 arrlist: [10, 5, 8,25] s: "web1" servers: - "app1" - "app2" - "web01" - "web1" f: 7.80 my_seq: [9, 8, "Vybhava",7.80, 'app1'] tasks: - name: Testing possible options with membership operator debug: msg: - "i = {{i}} and arrlist = {{ arrlist }}" - "check i in arrlist : {{ i in arrlist }}" - "check 100 in arrlist : {{ 100 in arrlist }}" - "check 100 not in arrlist : {{ 100 not in arrlist }}" - "check i not in arrlist : {{ i not in arrlist }}" - "Testing membership with number list done!" - "s = {{s}} and servers={{servers}}" - "Check s in servers : {{ s in servers }}" - "Check s not in servers : {{ s not in servers }}" - "Check web2 in servers : {{ 'web2' in servers }}" - "Check app2 in servers : {{ 'app2' in servers }}" - "Testing membership with strings list done!!" - "f = {{f}} and my_seq = {{my_seq}}" - "Check 9 in my_seq : {{ 9 in my_seq }}" - "Check i not in my_seq : {{ i not in my_seq }}" - "Check 'app1' in my_seq : {{ 'app1' in my_seq }}" - "Check s not in my_seq : {{ s not in my_seq }}" - "Check f in my_seq : {{ f in my_seq }}" - "Testing membership with sequance done!!!"
You know how to run the this playbook
The execution output is as follows:
Ansible membership operators in, not in example |
Keep watching for the new Ansible learning updates...
No comments:
Post a Comment