Reputation: 23
I have to perform the below steps.
Create a Playbook test.yml.
This playbook should copy the file (somefile.j2) to the Host machine's folder1, only if
somefile.j2 does not exist in host01.
By using vi editor you can add the tasks to test.yml.
[Hint: Use the stat and template module].
somefile.j2 is present at /root.
An inventory file named "myhosts" is present at /root
$ cat myhosts
host01 ansible_ssh_user=root
What should be the contents of test.yml?
Upvotes: 0
Views: 64
Reputation: 68254
Homework questions without "the work done so far to solve the problem and a description of the difficulty" is off-topic. But the conflict in the assignment, which might be considered "a practical, answerable problem that is unique to software development", deserves the answer.
The assignment requires to use the module stat
to find out whether the file exists or not. If it does not exist use the module template
to create it.
It is not necessary to use the module stat
. The module template
"will only transfer the file if the destination does not exist" when "force: no" (default yes). Such "idempotent" behavior of Ansible modules is essential, should be expected, and searched for.
Upvotes: 1