0

I am new with ansible/ansible tower and I've been trying it for some days and trying to copy file, installing software to other machines, and other things.

I have a doubt.

Let's say I have 1 control machine and 10 hosts. I want to copy, for example, 5 files into each host.

I run my playbook. My ansible can only reach 3 files (for example - due to some unknown error), so it copies only 3 files into all hosts. Now I watch this, and after the first job is done I make all the files available. I run my playbook again, and this time it copies all 5 files into all the hosts. Now can I make it, so that Ansible knows the hosts have the first 3 files, and in the second time I run the playbook, it knows it, and therefore, it only copies the remaining files into the hosts? The remaining 2 files.

And the same thing if a host is unreachable is unavailable for the first time. In the second job it should only copy all the files into that host. The remaining hosts which have 3 files it should only copy the remaining files.

techraf
  • 64,883
  • 27
  • 193
  • 198
fr0zt
  • 733
  • 4
  • 12
  • 30
  • Do you know of the synchronize module? http://docs.ansible.com/ansible/latest/synchronize_module.html – mghicks Nov 21 '17 at 21:17
  • yes. I'd like to know how is it possible to make it so that it does not overwirte anything when a file gets copied from control do host please. – fr0zt Nov 21 '17 at 22:24
  • I've check and the thing is. Copying files from control machine to host it doesn't not overwrite, unless a file is changed in the control machine. But If I use get_url it overwrites everything... – fr0zt Nov 22 '17 at 10:42

1 Answers1

1

Now, can I make it, so that Ansible knows the hosts have the first 3 files, and in the second time I run the playbook, it knows it, and therefore, it only copies the remaining files into the hosts?

There is nothing you need to do. With Ansible you define a desired state.

For example with copy module, you don’t tell Ansible to copy a file. Instead, you request Ansible to make sure a certain file on the target machine has desired content. If it already does, Ansible does not perform any action. If the file doesn't exist, or the file on the target has different content, Ansible copies the file.

Idempotency, as this feature is called, allows you to run the same playbook many times and the state will always remain consistent with the desired on.

This also means that if some task fails, re-running the playbook will by definition "continue" from the place it failed.

There is a small set of Ansible modules clearly marked as "non-idempotent", which do not provide this feature, but most are.

Ansible is not foolproof and one can write playbooks which are not idempotent, but this is power and responsibility of the programmer.

On top of that Ansible has a “retry”-mechanism for optimisation purposes.

techraf
  • 64,883
  • 27
  • 193
  • 198
  • Thanks. I understant why I have this issue. I am performing a download and unarchive of a file into hosts (using unarchive module), and after that I am copying some files from control machine into hosts (using copy module) (all in one playbook). What is happening is that every time I use unarchive module, although every file is the same, ansible is overwriting files in hosts. Do you how can I make it so that it does not overwrite if contents are the same? – fr0zt Nov 22 '17 at 13:59