bash - ansible - if statement and redirect to a file with shell module doesn't work -


i understand it's best use ansible modules as possible, reason, being forced use shell module.

i have date_list file list of dates:

20170811 20170802 20170812 , on.. 

i need compare dates ansible time shell module:

- name: read file date , compare server date , redirect file   shell: |     if [ {{ item.split('\n')[0] }} -lt ${{ gv_remote_date.stdout }} ];          echo {{ item.split('\n')[0] }} >> final_output     fi    args:      executable: /bin/bash    with_lines: "{{ date_list.stdout_lines }}" 

i no output @ all. in debug: can see it's switching items nothing in final_output file.

why not use native when statement:

- name: read file date , compare server date , redirect file   shell: echo {{ item }} >> final_output   args:     executable: /bin/bash   when: item | int < gv_remote_date.stdout | int   with_items: "{{ date_list.stdout_lines }}" 

or (to make idempotent):

- lineinfile:     dest: final_output     line: "{{ item }}"     state: "{{ (item | int < gv_remote_date.stdout | int) | ternary('present','absent') }}"   with_items: "{{ date_list.stdout_lines }}" 

this make sure line in file if should , line absent if condition false.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -