Let's say I manage file myfile.conf
with Ansible, e.g.:
- template:
src: "myfile.conf.j2"
dest: "/etc/myfile.conf"
I can then see the diff in a dry-run, like this:
$ ansible-playbook --check --diff myplaybook.yaml
Cool. But it seems to only display the diff when the file exists on the remote host. If the file is absent, I don't see the output other than task OK.
How do I tell Ansible to show the diff if the file is absent currently?
Perhaps similar to how Git would show a diff in a commit of a newly created file in style like with /dev/null
as base in the diff:
--- /dev/null
+++ b/myfile.conf.j2
Works for me (ansible 2.7.9):
Perhaps it is version-dependent or you are hitting
max_diff_size
(default 104448 bytes).That use case is not really implemented in Ansible but you might be able to get the output you want by adding dummy content to the file if it doesn't exist before creating it, like this: