My preference in how to achieve this in a more ansible way, is using slurp,
and then checking the returned contents:

- name: Get /root/.bashrc
  slurp:
    src:  /root/.bashrc
  register: root_bashrc

- name: Enable bash-completion for root user
  copy:
    src: /etc/skel/.bashrc
    dest: /root/.bashrc
    remote_src: true
  when: "'/etc/bash_completion' not in root_bashrc.content|b64decode"

I also replaced your command to copy the file, with the copy module, using
remote_src=true

On Sun, Feb 26, 2017 at 7:36 AM, Stéphane Klein <[email protected]>
wrote:

>
> Le vendredi 24 février 2017 22:40:05 UTC+1, Kai Stian Olstad a écrit :
>>
>> On 24. feb. 2017 21:56, Stéphane Klein wrote:
>> > Le vendredi 24 février 2017 21:26:38 UTC+1, Kai Stian Olstad a écrit :
>> >>
>> >>> Do you know a better solution?
>> >>
>> >> What I would do is put the correct .bashrc in Ansible and just use the
>> >> copy module to copy it to the host(s).
>> >>
>> >>
>> > I would like copy only if bash_completion isn't already present in
>> .bashrc
>>
>> Then you don't have much choice but go for the solution you posted.
>>
>> But to make the output nicer I would replace "ignore_errors: True"
>> with
>>
>>    failed_when: False
>>
>> or
>>
>>    failed_when: check_bashcompletion_enabled.rc > 1
>>    changed_when: check_bashcompletion_enabled.rc == 1
>>
>>
>> What is it about your solution you don't like?
>>
>>
> Yes, thank it's better.
>
> --
> 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/69f54eab-e80d-4626-95b8-c3187f324428%40googlegroups.
> com
> <https://groups.google.com/d/msgid/ansible-project/69f54eab-e80d-4626-95b8-c3187f324428%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Matt Martz
@sivel
sivel.net

-- 
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/CAD8N0v8UV1fm4CL2UaXgoomesOcjEA_s7G40s12SaedaXtYSNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to