Hi, I wish to compare the file in client machine with the file in server machine. I wish to know if the contents are the same. How do I do it?
tasks:
- name: Compare 2 files
action:
How do I input my action statement?
Many thanks.
Hi, I wish to compare the file in client machine with the file in server machine. I wish to know if the contents are the same. How do I do it?
tasks:
action:
How do I input my action statement?
Many thanks.
you can use copy: to compare if both files are differnt, using --check to not overrite.
and --diff will do an actual diff.
Hi Brian,
Thank you for your reply. I am new to ansible so i am sorry if the question i am asking in of low level.
I wish to compare file new1 on client computer with file newfile on server computer. I tried this:
tasks:
I got this error: msg: this module requires key=value arguments.
How can i know which key or value it requires?
Thanks a lot.
As far as i know, --check should be passed when running the playbook, Not within the playbook.
e.g. from Doc site.
ansible-playbook foo.yml --check
http://www.ansibleworks.com/docs/playbooks2.html#check-mode-dry-run-check
Regards,
Yes, i saw this too. But how does Ansbile knows which file i want it to compare to? My objective is to compare a file on client with another file on the server.
Yes, i saw this too. But how does Ansbile knows which file i want it to
compare to? My objective is to compare a file on client with another file
on the server.
I don't think there's a module that will do that for you. I suggest you
look at the `fetch' module with which you can retrieve a file, then do
the comparison manually using `command' module and md5sum program.
Alternatively, you can `copy' the file to the remote and do the
checksumming there. Either way, I think you've have to transfer the
file.
Check the documentation of the modules (ansible.cc/docs/modules) which
detail all the options or use the `ansible-doc' command on an individual
module to find supported options.
-JP
Create a Playbook with copy task:
- name: test
hosts: all
sudo: True
tasks:- name: whatever
action: copy src=/var/repository/smb.j2 dest=/etc/samba/smb.conf
Run Playbook with --check and --diff:
ansible-playbook diff.yml -kK -u admin --limit=HostA --check --diff
This will not actually copy your file to remote host, but will do diff comparison between those files
Edgars
for copy and template modules, src= is on the machine you execute ansible from, dest= is on the target machine, that is how you can get them to compare (using --check and --diff options on the command line).
Thanks everyone for your help