hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.31k stars 4.43k forks source link

Vagrant tries to install epel for amazon linux2 during `ansible_local` provisioning #12110

Open mykelalvis opened 3 years ago

mykelalvis commented 3 years ago

Vagrant version

❯ vagrant -v
Vagrant 2.2.14

Host operating system

❯ uname -a
Linux ********.org 5.9.13-200.fc33.x86_64 #1 SMP Tue Dec 8 15:42:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Guest operating system

config.vm.box = "bento/amazonlinux-2"

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  # config.vm.box = "centos/8"
  config.vm.box = "bento/amazonlinux-2"
  config.vm.network "forwarded_port", guest: 8080, host: 18080
  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.memory = "2048"
  end

  # An easy package update
  # config.vm.provision "shell", inline: <<-SHELL
  #   sudo yum -y update
  # SHELL

  config.vm.provision "ansible_local" do |ansible|
    ansible.playbook = "playbook.yml"
    ansible.verbose = true
  end
end

playbook.yml


---
# 
- name: 'Configure this server'
  hosts: default
  become: true
  handlers:
    - name: restart_service
      service: 
        name: service
        state: restarted

  tasks:
    - name: Install Sudo
      package:
        name: sudo
        state: latest

Debug output

link to a GitHub Gist containing the complete debug output

Expected behavior

Expected ansible_local to install Ansible and then execute playbook

Actual behavior

Vagrant appeared to 404 trying to install EPEL

Steps to reproduce

  1. Put Vagrantfile and jenkins.yml into local directory
  2. vagrant up
  3. Attempt to reconcile your life choices with what you actually wanted and then become despondent about the inevitable heat death of the universe.

References

mykelalvis commented 3 years ago

Workarounds that have worked for me:

  1. Force Vagrant to install ansible2 to image before executing ansible, using amazon-linux-extras
  2. Don't run ansible_local against Amazon Linux2. Installing ansible on the host system and then using the ansible provisioner is an option if you don't want ansible installed on the guest.
Vagrant.require_version  ">= 1.8  "
Vagrant.configure("2") do |config|
  config.vm.box = "bento/amazonlinux-2"
  config.vm.provider "virtualbox" do |vb|
    vb.name = "test"
    vb.gui = false
    vb.memory = "2048"
    vb.cpus = 1
    vb.check_guest_additions = false
  end

  # Easy update
  config.vm.provision "shell", inline: <<-SHELL
    sudo yum -y update
    sudo amazon-linux-extras install ansible2  
  SHELL

  config.vm.provision "ansible_local" do |ansible|
    ansible.become = true
    ansible.galaxy_role_file = "ansible_requirements.yml"
    ansible.galaxy_roles_path = "/etc/ansible/roles"
    ansible.galaxy_command = "sudo ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force"
    ansible.playbook = "playbook.yml"
    ansible.verbose = false
  end
end