I need to parse a text file for gaps in a numbered list, then select the first missing number as an Ansible variable.
For example, with a list that looks like this:
100
101
102
103
104
106
107
109
110
My requirement is to identify the first integer missing in the sequence 100..111 from this file, in this case, it would need to select 105.
I am currently using lineinfile to parse the text:
- lineinfile:
dest: target.txt
regexp: "{{ item }}"
state: absent
check_mode: yes
register: search
loop: "{{ range(100, 111) | list }}"
This gives me a dictionary called search that contains, among other things, a found value for each number. I'd like to filter the dictionary to select the first number occurring with value found: '0', but have so far been unsuccessful.
Due to an outdated version of Ansible and Jinja2 (that can't be updated for reasons), I don't have access to the selectattr or rejectattr filters, which I know would be the preferred way of accomplishing this. I'm currently trying to develop a workaround using json_query but haven't had any luck yet.
I don't care how cumbersome the final code is.