diff --git a/plugins/provisioners/ansible/cap/guest/epel/ansible_install.rb b/plugins/provisioners/ansible/cap/guest/epel/ansible_install.rb deleted file mode 100644 index 6ae10b091..000000000 --- a/plugins/provisioners/ansible/cap/guest/epel/ansible_install.rb +++ /dev/null @@ -1,39 +0,0 @@ - -module VagrantPlugins - module Ansible - module Cap - module Guest - module EPEL # Extra Packages for Enterprise Linux (for RedHat-family distributions) - module AnsibleInstall - - # This should work on recent Fedora releases, and any other members of the - # RedHat family which supports YUM and http://fedoraproject.org/wiki/EPEL - def self.ansible_install(machine) - - configure_epel = </etc/yum.repos.d/epel-bootstrap.repo -[epel] -name=Bootstrap EPEL -mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-\$releasever&arch=\$basearch -failovermethod=priority -enabled=0 -gpgcheck=0 -EOM - -yum --assumeyes --quiet --enablerepo=epel install epel-release -rm -f /etc/yum.repos.d/epel-bootstrap.repo -INLINE_CRIPT - - ansible_is_installable = machine.communicate.execute("yum info ansible", :error_check => false) - if ansible_is_installable != 0 - machine.communicate.sudo(configure_epel) - end - machine.communicate.sudo("yum --assumeyes --quiet --enablerepo=epel install ansible") - end - - end - end - end - end - end -end diff --git a/plugins/provisioners/ansible/cap/guest/fedora/ansible_install.rb b/plugins/provisioners/ansible/cap/guest/fedora/ansible_install.rb new file mode 100644 index 000000000..badaace03 --- /dev/null +++ b/plugins/provisioners/ansible/cap/guest/fedora/ansible_install.rb @@ -0,0 +1,25 @@ + +module VagrantPlugins + module Ansible + module Cap + module Guest + module Fedora + module AnsibleInstall + + def self.ansible_install(machine) + if dnf?(machine) + machine.communicate.sudo("dnf -y install ansible") + else + machine.communicate.sudo("yum -y install ansible") + end + end + + def self.dnf?(machine) + machine.communicate.test("/usr/bin/which -s dnf") + end + end + end + end + end + end +end diff --git a/plugins/provisioners/ansible/cap/guest/redhat/ansible_install.rb b/plugins/provisioners/ansible/cap/guest/redhat/ansible_install.rb new file mode 100644 index 000000000..8e17908e4 --- /dev/null +++ b/plugins/provisioners/ansible/cap/guest/redhat/ansible_install.rb @@ -0,0 +1,29 @@ + +module VagrantPlugins + module Ansible + module Cap + module Guest + module RedHat + module AnsibleInstall + + # This should work on recent Fedora releases, and any other members of the + # RedHat family which supports YUM and http://fedoraproject.org/wiki/EPEL + def self.ansible_install(machine) + + epel = machine.communicate.execute("#{yum_dnf(machine)} repolist epel | grep -q epel", :error_check => false) + if epel != 0 + machine.communicate.sudo('sudo rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-`rpm -E %dist | sed -n \'s/.*el\([0-9]\).*/\1/p\'`.noarch.rpm') + end + + machine.communicate.sudo("#{yum_dnf(machine)} -y --enablerepo=epel install ansible") + end + + def self.yum_dnf(machine) + machine.communicate.test("/usr/bin/which -s dnf") ? "dnf" : "yum" + end + end + end + end + end + end +end diff --git a/plugins/provisioners/ansible/plugin.rb b/plugins/provisioners/ansible/plugin.rb index 3be60f8ad..b0e0aa0ed 100644 --- a/plugins/provisioners/ansible/plugin.rb +++ b/plugins/provisioners/ansible/plugin.rb @@ -55,9 +55,14 @@ module VagrantPlugins Cap::Guest::Ubuntu::AnsibleInstall end + guest_capability(:fedora, :ansible_install) do + require_relative "cap/guest/fedora/ansible_install" + Cap::Guest::Fedora::AnsibleInstall + end + guest_capability(:redhat, :ansible_install) do - require_relative "cap/guest/epel/ansible_install" - Cap::Guest::EPEL::AnsibleInstall + require_relative "cap/guest/redhat/ansible_install" + Cap::Guest::RedHat::AnsibleInstall end guest_capability(:suse, :ansible_install) do