python - Ansible: given a list of ints in a variable, define a second list in which each element is incremented -


let's assume have ansible variable list_of_ints.

i want define incremented_list, elements obtained incrementing fixed amount elements of first list.

for example, if first variable:

--- # file: somerole/vars/main.yml  list_of_ints:   - 1   - 7   - 8 

assuming increment of 100, desired second list have content:

incremented_list:   - 101   - 107   - 108 

i thinking of on lines of:

incremented_list: "{{ list_of_ints | map('add', 100) | list }}" 

sadly, ansible has custom filters logarithms or powers, not basic arithmetic, can calculate log10 of numbers, not increment them.

any ideas, apart pull request on https://github.com/ansible/ansible/blob/v2.1.1.0-1/lib/ansible/plugins/filter/mathstuff.py ?

this it:

---  - hosts: localhost   connection: local   vars:     incremented_list: []     list_of_ints:       - 1       - 7       - 8     incr: 100   tasks:    - set_fact:        incremented_list: "{{ incremented_list + [ item + incr ]  }}"      no_log: false      with_items: "{{ list_of_ints }}"     - name: show cntr      debug: var=incremented_list 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

php - What are the best practices for creatiang a "settings" model in Laravel 5? -