neillturner / kitchen-ansible

Ansible Provisioner for Test Kitchen
Other
350 stars 134 forks source link

Fix Ansible install for Fedora 30 #309

Closed b00ga closed 5 years ago

b00ga commented 5 years ago

With the impending end-of-support for Python 2.x in Jan 2020, Fedora has started switching all Python support to 3.x. Fedora 30 has been the removal of Python 2.x packages (see https://fedoraproject.org/wiki/Changes/Mass_Python_2_Package_Removal). Because of this, there is no longer a python2-dnf package, so the dnf install fails.

This command adds a check for Fedora release. If less than or equal to 28, then use the previous install command. Starting with 29, Fedora's Ansible is python3 based, so flip libselinux and dnf python packages to be their python3 counterparts.

b00ga commented 5 years ago

Tested against Fedora 28, 29, and 30 from official Fedora vagrant cloud box.

kitchen.yml

---
driver:
  name: vagrant
  customize:
    cpus: 2
    memory: 2048

provisioner:
  name: ansible_playbook
  hosts: all
  require_chef_for_busser: false

platforms:
  - name: fedora/30-cloud-base
  - name: fedora/29-cloud-base
  - name: fedora/28-cloud-base

suites:
  - name: default
    run_list:
    attributes:

and default.yml playbook to exercise (note if you have the wrong libselinux python binding, the file task won't fail, but it also won't set the requested SELinux settings. This is how I discovered that this bug also effects Fedora 29 which appears to be when Ansible switched to py3 in Fedora):

---
- hosts: all

  tasks:
  - name: Install a package
    dnf:
      name: 'zsh'
      state: latest

  - name: Create a file with SELinux context
    file:
      path: '/tmp/kitchen-ansible.txt'
      owner: vagrant
      group: vagrant
      setype: 'etc_t'
      state: touch