Thank you James, its working fine.

Thanks,
Deepan M

On Monday, February 25, 2019 at 6:38:36 PM UTC+5:30, Deepan M wrote:
>
>  
>
> Hello,
>
> Can someone please help to solve my request?
>
> with blockinfile module, I'm looking for option to check the entries 
> whether its present or not! if not then entries have to be added by play.
>
> As per below my playbook, its working partially, like its appending even 
> if the entries are already present but actually i'm looking that play 
> should ignore if already entries are exists and incase not present then it 
> should added.
>
>
>
> *Playbook:-*
> cat resolv_add.yml
> ---
> - hosts: resolv
>   become: yes
>   tasks:
>   - name: check the presence of lines
>     shell: cat /tmp/resolv.conf |egrep "Hello the world|i'm here|is it 
> working"
>     register: result
>     ignore_errors: yes
>   - debug: msg="{{result.stdout}}"
>   - name: add lines below lines if not exists
>     blockinfile:
>       marker: ""
>       block: |
>             Hello the world
>             i'm here
>             is it working
>       path: /tmp/resolv.conf
>       state: present
>     changed_when: result.stdout.find('exists') == -1
>
>
> *Execution Output:-*
>
>  ansible-playbook resolv_add.yml
> SUDO password:
>
> PLAY [resolv] 
> ************************************************************************************************************************
>
> TASK [Gathering Facts] 
> ***************************************************************************************************************
> ok: [usa7061lv1771]
>
> TASK [check the presence of lines] 
> ***************************************************************************************************
> changed: [usa7061lv1771]
>
> TASK [debug] 
> *************************************************************************************************************************
> ok: [usa7061lv1771] => {
>     "msg": "Hello the world\ni'm here\nis it working"
> }
>
> TASK [add lines below lines if not exists] 
> *******************************************************************************************
> changed: [usa7061lv1771]
>
> PLAY RECAP 
> ***************************************************************************************************************************
> usa7061lv1771              : ok=4    changed=2    unreachable=0    failed=0
>
> *Remote server output:-*
>  cat resolv.conf
>
> Hello the world
> i'm here
> is it working
>
> Hello the world
> i'm here
> is it working
>
> Thanks,
> Deepan M
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4578806c-2d4e-4707-8057-a677f6363dce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to