On 25. juli 2017 19:18, Josef Fortier wrote:
> I attempted a command to rm host_keys to regenerate
>
> - name: delete host keys
> command: rm /etc/ssh/*_key*
>
> This issues a warning, and does not actually delete the files
> I added a -f flag to rm, thinking that maybe some shell condition caused
> the command module to return early, but that had no effect.
> Ansible gives a warning about rm, suggesting I use the file module, but
> that seems problematic, adding a lot of logic to a simple task.
> Regardless, I'd not expect it to veto but merely suggest.
It is just a informational message, you can set "warn: False" on the
task and the messages won't show.
It's also possible to turn of this informational warning message in
ansible.cfg.
> I was able to get it working with the shell module.
Command module does not support globs so you would need to use shell
with globs.
> 2) Is there a file module way to bulk remove on glob/wildcard that's
> elegant?
> I'm trying fairly hard to avoid lot's of register calls, as they make the
> logic flow much harder to follow.
To do is the more Ansible way, you need two task.
First one with the find module, that support globs or regexp, register
the output in a variable, the use the file module to delete the list the
find module returned.
--
Kai Stian Olstad