If one writes a constant in Python, then one uses uppercase:
SOME_CONSTANT = "helloworld"
Now I wonder how to define constants in Ansible. My first impression was to use the same convention as in Python as Ansible is written in python, but when one checks the variables information page then this does not seem to be a best practice.
Current approach
https://github.com/030/ansible-firefox/blob/master/vars/main.yml
---
firefox_download: /tmp/firefox-{{ firefox_version }}.tar.bz2
firefox_bin: "{{ firefox_home }}/firefox/firefox"
https://github.com/030/ansible-firefox/blob/master/tasks/main.yml
- name: Download.
get_url:
url: https://ftp.mozilla.org/pub/firefox/releases/{{ firefox_version }}/linux-x86_64/en-US/firefox-{{ firefox_version }}.tar.bz2
dest: /tmp/firefox-{{ firefox_version }}.tar.bz2
checksum: "{{ firefox_checksum }}"
Discussion
I am considering to define https://ftp.mozilla.org/pub/firefox/releases/{{ firefox_version }}/linux-x86_64/en-US/firefox-{{ firefox_version }}.tar.bz2
as a constant in the vars/main.yml
, but I did not see any other ansible roles that define constants as:
FIREFOX_DOWNLOAD_URL: https://ftp.mozilla.org/pub/firefox/releases/{{ firefox_version }}/linux-x86_64/en-US/firefox-{{ firefox_version }}.tar.bz2
while this is valid python and the convention to write constants.
One could argue that an Ansible constant could be defined in the default/main.yml
, but on the other hand, as a CONSTANT is immutable it should not be possible to overwrite it and should reside in vars/main.yml
.