Ansible: `lsb_release` Variable

The lsb_release -sc command displays the release codename of a Linux distribution in a short format.

You can often meet this command while adding APT repositories, e.g. sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main".

To get the output of the lsb_release -sc command in Ansible, there is no actually a need to execute this command, as the ansible_distribution_release fact in Ansible already stores this information in the required format.

This note shows how to refer to the output of the lsb_release -sc command in Ansible using the ansible_distribution_release fact.

Cool Tip: Ansible Playbook – Print Variable & List All Variables! Read more →

lsb_release in Ansible

You can refer to the lsb_release -sc command’s output using the Ansible’s built-in ansible_distribution_release variable as follows:

- name: "Ansible | Print 'lsb_release'"
  debug:
    msg: "{{ ansible_distribution_release }}"

Sample output:

TASK [ansible_variables : Ansible | Print 'lsb_release'] ****************************
ok: [127.0.0.1] => {
    "msg": "uma"
}

You can compare with the output of the lsb_release -cs executed on the same machine:

$ lsb_release -cs
uma

Cool Tip: How to compare version numbers in Ansible! Read more →

Leave a Reply