AnsibleSnips

From Cygnus Alpha
Jump to: navigation, search


Playbook with tasks & conditionals

---
- name: Install conda to appropriate hosts
  hosts: localhost
  become: true
  vars:
    cronenable: false
  tasks:
    - name: debug
      debug:
        msg: "Turnips"
    - name: crontab
      file:
        path: /etc/cron.d
        state: directory
    - name: cron
      cron:
        name: testcron
        cron_file: testcron
        user: root
        job: 'echo Hello > /dev/null'
        disabled: '{{ not cronenable }}'
    - name: test
      command: cat /etc/cron.d/testcron

Variable Precedence

Lowest

  • role defaults [1]
  • inventory file or script group vars
  • inventory group_vars/all
  • playbook group_vars/all
  • inventory group_vars/*
  • playbook group_vars/*
  • inventory file or script host vars
  • inventory host_vars/*
  • playbook host_vars/*
  • host facts / cached set_facts
  • inventory host_vars/*
  • playbook host_vars/*
  • host facts
  • play vars
  • play vars_prompt
  • play vars_files
  • role vars (defined in role/vars/main.yml)
  • block vars (only for tasks in block)
  • task vars (only for the task)
  • role (and include_role) params
  • include params
  • include_vars
  • set_facts / registered vars
  • extra vars (always win precedence)

Highest

See: https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable