Ansible - idempotent

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"


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

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


Web design by yours truely - me, myself, and I   |   |