Bootstrap FreeKB - Ansible - idempotent
Ansible - idempotent

Updated:   |  Ansible articles

The term idempotent means that if you do something once vs. doing the same thing multiple times, the result will be exactly the same. For example, let's say foo.txt contains the text "Hello World". The lookup module can be used to store the content of foo.txt in a variable. In this example, the content of foo.txt is stored in a variable named "foo".

  foo: "{{ lookup('file', 'foo.txt') }}"


The debug module is used to print the foo variable. Notice the double curley braces {{ ... }}. Jinja2 uses double curley braces for variables.

- name: "display the contents of foo.txt"
    msg: "{{ foo }}"


The following will be displayed. As long as foo.txt is not modified, no matter how many times you perform this action, the result will always be the same, in that Hello World will be displayed. In this way, this action is idempotent .

TASK [display the contents of foo.txt]
ok: [localhost] => {
    "msg": "Hello World"


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee


Add a Comment

Please enter 0f4772 in the box below so that we can be sure you are a human.