0

NOTE: Part of Puppet to Ansible migration evaluation. Ansible noob.

CentOS 7 returns operatingsystemrelease (puppet) or ansible_distribution_version (ansible) as 7.2.1511 instead of just 7.2. So in puppet we use the following hack.

# Hack for CentOS 7. operatingsystemrelease includes third part of release version eg 7.2.1511
if [[ "$(facter operatingsystem)" == "CentOS" && "$(facter operatingsystemmajrelease)" == "7" ]]
then
    export FACTER_operatingsystemrelease=$(facter operatingsystemmajrelease).$(facter --json os | grep minor | awk '{ print $2 }' | tr '",' ' ' | sed -e 's/ //g')
fi

Setting environment variable FACTER_operatingsystemrelease overrides the operatingsystemrelease value. This needs to happen only for CentOS 7. CentOS 6 works fine.

What would be the equivalent way to make this work in Ansible?

techraf
  • 64,883
  • 27
  • 193
  • 198
MavWolverine
  • 846
  • 1
  • 9
  • 24

1 Answers1

0

You can override facts as any other variable:

set_fact: ansible_distribution_version="{{ ansible_distribution_version | regex_replace('7\.2\.\d+','7.2') }}"
when: ansible_distribution == 'CentOS'
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193