Idempotence and Random Variables in Ansible

后端 未结 3 2024
长情又很酷
长情又很酷 2021-02-19 20:26

Is there a way to guarantee idempotence for playbooks that use randomly generated variables?

For example, I want to setup my crontabs to trigger emails on multiple serve

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-19 20:46

    Instead of a random value, you could get something related to the node, like an hash of the hostname or the last byte of the ip address.

    This is an example:

    - name: Get a pseudo-random minute 
      shell: expr $((16#`echo "{{inventory_hostname}}" | md5sum | cut -c 1-4`)) % 30
      register: minute
      changed_when: false
    

提交回复
热议问题