Setup & Provision Fedora Server using Ansible


This tutorial walks you through how to setup & provision a Fedora Server using Vagrant and Ansible. Ansible will be used to automatically install and configure a Vagrant box (virtual machine) for us.


EBS local helloworld

Writing our Vagrantfile

# Vagrantfile
Vagrant.configure("2") do |config| = "roboxes/fedora28"

    config.vm.define 'fedora' do |node|
        node.vm.hostname = 'fedora.local'
        node.vm.provision 'ansible' do |ansible|
            ansible.playbook = 'main.yml'

Writing our Playbook

Playbooks is what Ansible uses for configuration management.

The yaml code below is a simple playbook that installs a Fedora Server, then installs a python package in order to disable SELinux.

# main.yml
- hosts: Fedora # name of the box - aka a *play* (multiple hosts refers to *plays*)
  become: true # everything will become sudo
  tasks: # represents things - a calls to an ansible module
  - name: Install libselinux-python # name of first task
    dnf: # fedora uses dnf package manager to install modules 
      name: "libselinux-python" # name of package we are installing
      state: present # ensures the desired package is installed
  - name: Disable selinux # name of second task
    selinux: # defining it
      state: disabled # disabling it

This .yml is specficially runs the Fedora Server in headless mode, which is handy for testing purposes.

Final output

➜  vagrant-ansible vagrant up
==> vagrant: A new version of Vagrant is available: 2.2.7 (installed version: 2.2.6)!
==> vagrant: To upgrade visit:

Bringing machine 'fedora' up with 'virtualbox' provider...
==> fedora: Box 'roboxes/fedora28' could not be found. Attempting to find and install
    fedora: Box Provider: virtualbox
    fedora: Box Version: >= 0
==> fedora: Loading metadata for box 'roboxes/fedora28'
    fedora: URL:
==> fedora: Adding box 'roboxes/fedora28' (v2.0.6) for provider: virtualbox
    fedora: Downloading:
    fedora: Download redirected to host:
==> fedora: Successfully added box 'roboxes/fedora28' (v2.0.6) for 'virtualbox'!
==> fedora: Importing base box 'roboxes/fedora28'...
==> fedora: Matching MAC address for NAT networking...
==> fedora: Checking if box 'roboxes/fedora28' version '2.0.6' is up to date...
==> fedora: Setting the name of the VM: vagrant-ansible_fedora_1582472543600_21194
==> fedora: Pruning invalid NFS exports. Administrator privileges will be required...
    fedora: Running ansible-playbook...

PLAY [fedora] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [fedora]

TASK [Install libselinux-python] ***********************************************
changed: [fedora]

TASK [Disable selinux] *********************************************************
[WARNING]: SELinux state temporarily changed from 'enforcing' to 'permissive'.
State change will take effect next reboot.

changed: [fedora]

PLAY RECAP *********************************************************************
fedora    : ok=3  changed=2  unreachable=0  failed=0  skipped=0  rescued=0  ignored=0

So when we open the newly created Fedora Vagrant box we can see it’s ran without a GUI interface.

Configuring Fedora to become a workstation

Now that our headless Fedora Server is working correctly, we can rewrite our .yml file to enable a graphical interface, as well as install a few packages.

# main.yml (revised)
- hosts: fedora
  become: true
  - name: Set default target to graphical
    shell: systemctl set-default graphical # enable graphical interface
  - name: Install lxde & sundry development tools # name of new task
      name: "" # for loop to install items below
      state: present
    with_items: # list of items dnf will install
      - '@Lxde desktop'
      - awscli
      - jq
      - docker
      - npm

After using vagrant provision, we can reboot our vm, and be greeted with a graphical interface.

Graphical Fedora

Enabling the Docker daemon

Next, we’re going to add additional plays to our Playbook but installing the Docker daemon onto our Fedora server.

# main.yml (revised)
- hosts: fedora
  become: true
  - name: Set default target to graphical
    shell: systemctl set-default graphical
  - name: Install lxde & sundry development tools
      name: ""
      state: present
      - '@Lxde desktop'
      - awscli
      - jq
      - docker
      - npm
  - name: Enable the Docker daemon
      name: docker
      state: started
      enabled: yes
  - name: Ensure the docker group exists
      name: docker
      state: present
  - name: Add vagrant user to Docker group
      name: vagrant
      append: yes
      group: docker

Voila, we can now see any list of docker containers.

Docker Fedora


This is a simple walk-through on how to use Ansible to spin up a Vagrant box. We wrote a basic playbook that doesn’t do all that much other than enabling services, and installing a bunch of packages.


Ansible Official Documentation

Vagrant Official Documentation