Re: [ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-12-21 Thread Vladimir Botka
On Wed, 21 Dec 2022 16:30:03 +0500 farrukh ahmed wrote: > blockinfile: > path: "{{ini_file_path}}" # set in defaults > marker: ";# {mark} ANSIBLE MANAGED BLOCK ###" > block: "{{ item.param }}" > loop: > - { param: "display_errors = {{service_configurations.display_errors | > d(omit) }}"} > - { pa

Re: [ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-12-21 Thread farrukh ahmed
Hello Team, I have progressed but still not achieved my target with *blockinfile * module. It should be updated the both items, as I passed both variables but It just updated the last item only i.e (memory_limit) Here is my play: - name: update php configurations blockinfile: path: "{{ini_file_pa

Re: [ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-12-20 Thread Dick Visser
Hii On Tue, 20 Dec 2022 at 12:47, farrukh ahmed wrote: > > Can we do the same with blockinfile? Maybe. But, what one can do, is not always what one should do - see below. > PS: It is mandatory for me to do this with the blockinfile module. This is not correct - the file should not be edited at

Re: [ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-12-20 Thread farrukh ahmed
Can we do the same with blockinfile? For instance, if the variable is not found then omit only that item and move on to the next item and update it. Here is my play - name: insert/update php configurations in App_config_file blockinfile: path: "/etc/php/7.4/fpm/php.ini_bak" marker: ";# {mark} ANSI

Re: [ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-08-05 Thread farrukh ahmed
Thanks @utoddl for your time and reply. when: item.line is not search(omit) This solution actually worked for me. Thanks & regards, FARRUKH On Friday, August 5, 2022 at 5:22:03 PM UTC+5 uto...@gmail.com wrote: > That "when:" should be > > when: item.line is not search(omit) > > On Friday,

Re: [ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-08-05 Thread Todd Lewis
That "when:" should be when: item.line is not search(omit) On Friday, August 5, 2022 at 8:03:34 AM UTC-4 Todd Lewis wrote: > - name: "Update Redis Parameters in {{ redis_config_path }}" > lineinfile: > path: "{{ redis_config_path }}" > backrefs: yes > regexp

Re: [ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-08-05 Thread Todd Lewis
- name: "Update Redis Parameters in {{ redis_config_path }}" lineinfile: path: "{{ redis_config_path }}" backrefs: yes regexp: "{{ item.regexp }}" line: "{{ item.line }}" when: item.line is match(omit) with_items: - { regexp: '^maxmemor

Re: [ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-08-05 Thread Stefan Hornburg (Racke)
On 05/08/2022 13:31, farrukh ahmed wrote: Thanks for your reply Vladimir Botka. This is my actual case:  defaults > main.yml --- # defaults file for redis_configs redis_config_path: /etc/redis/redis.conf # Default Params Values MAX_MEM: 3000 TCP_KEEPALIVE: 0 TCP_BACKLOG: 511 MAX_CLIENTS: 15000

Re: [ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-08-05 Thread farrukh ahmed
Thanks for your reply Vladimir Botka. This is my actual case: defaults > main.yml --- # defaults file for redis_configs redis_config_path: /etc/redis/redis.conf # Default Params Values MAX_MEM: 3000 TCP_KEEPALIVE: 0 TCP_BACKLOG: 511 MAX_CLIENTS: 15000 TIMEOUT: 1500 And this is: Tasks > main

Re: [ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-08-05 Thread Vladimir Botka
On Thu, 4 Aug 2022 23:43:59 -0700 (PDT) farrukh ahmed wrote: > with_items: > - { regexp: '^text1', line: "text1 = {{ VAR1 }}", when: VAR1 is defined } > - { regexp: '^text2', line: "text2 = {{ VAR2 }}" } > - { regexp: '^text3', line: "text3 = {{ VAR3 }}" } Set *default* to avoid errors, ad

[ansible-project] Lineinfile - Skip/Update an item inside "with_items" using conditions

2022-08-04 Thread farrukh ahmed
I have a question. Can an item inside "with_items" or "loop" be skipped? using condition "when some_variable is not defined" ? Here is my play. *- name: "Update text in the file" lineinfile:path: /path-to-the-file/backrefs: yesregexp: "{{ item.regexp }}"line: "{{ ite