#ansible #vagrant #yum #vagrantfile
#ansible #vagrant #вкуснятина #vagrantfile
Вопрос:
Когда я запускаю vagrant на своем Centos6, он показывает эту ошибку:
==> w3package_v2: запуск provisioner: ansible_local… w3package_v2: установка Ansible… Следующая команда SSH ответила ненулевым статусом выхода. Vagrant предполагает, что это означает сбой команды!
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 Stdout from the command: Stderr from the command: curl: (22) The requested URL returned error: 403 Forbidden error: skipping https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
Ниже приведен Vagrantfile:
VAGRANTFILE_API_VERSION = "2"
APP_NAME = "w3package_v2"
VM_NAME = "w3package_v2"
GUEST_IP = "192.168.33.59"
# [note]
# * for VirtualBox users:
# vagrant-vbguest plugin required.
# Run `vagrant plugin install vagrant-vbguest`.
# * for Windows10 Hyper-V users:
# Enable SMB 1.0 (for Windows 10 Hyper-V users)
if !Object.const_defined?('VagrantVbguest') || !Vagrant.has_plugin?('vagrant-vbguest')
puts "ERROR: vagrant-vbguest plugin is required. Run `vagrant plugin install vagrant-vbguest`."
abort
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define VM_NAME
config.vm.box = "bento/centos-6"
config.vm.boot_timeout = 3600
config.vm.network :private_network, ip: GUEST_IP
config.vm.network :public_network, bridge: 'en0: Wi-Fi (AirPort)'
if OS.windows?
config.vm.synced_folder ((File.expand_path(File.dirname(__FILE__) "/../../../..")).gsub("/","\")), "/var/www/" APP_NAME "/current", owner: "vagrant", type: "virtualbox", automount: true, SharedFoldersEnableSymlinksCreate: true
else
config.vm.synced_folder "../../../..", "/var/www/" APP_NAME "/current", id: "vagrant", nfs: true
end
config.ssh.insert_key = false
config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
config.vm.provider :virtualbox do |vb|
vb.name = VM_NAME
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "100"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["setextradata", :id, "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled", 0]
if OS.windows?
vb.customize ["sharedfolder", "add", :id, "--name", VM_NAME, "--hostpath", (("//?/" File.expand_path(File.dirname(__FILE__) "/../../../..")).gsub("/","\"))]
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/" VM_NAME, "1"]
config.vm.provision "shell", path: "../../configuration/vagrant-vbmount.sh", args: VM_NAME
end
end
config.vm.provider :hyperv do |h, override|
h.enable_virtualization_extensions = true
h.linked_clone = true
override.vm.synced_folder ((File.expand_path(File.dirname(__FILE__) "/../../../..")).gsub("/","\")), "/var/www/" APP_NAME "/current", type: "smb", automount: true, SharedFoldersEnableSymlinksCreate: true
end
config.vm.provision "ansible_local" do |ansible|
ansible.limit = "all"
ansible.compatibility_mode = "2.0"
ansible.playbook = "/var/www/" APP_NAME "/current/tools/provisioning/configuration/vagrant-local.yml"
ansible.verbose = "v"
end
end
## ref https://qiita.com/dd511805/items/8cb7e524e0d790c24af1
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
end
И это мой основной файл.yml:
- name: check dir /var/www
shell: '[ -e /var/www ]; echo $?'
register: result
- name: mkdir /var/www
command: mkdir /var/www
when: result.stdout != '0'
- name: change locale
shell: 'cp /usr/share/zoneinfo/Japan /etc/localtime'
- name: install python-selinux
yum: pkg=libselinux-python state=latest
- name: disable selinux
selinux: state=disabled
- name: install epel-repo
yum: pkg=epel-release state=latest
- name: fix CentOS-Base.repo
template: src=CentOS-Base.repo dest=/etc/yum.repos.d/CentOS-Base.repo
- name: update yum
yum: name=* state=latest
Как я мог это исправить?
Комментарии:
1. Ну, вы можете получить этот .rpm вручную? Потому что в противном случае автоматизация предназначена только для автоматизации вещей, которые можно было бы сделать вручную. Кроме того, ваш опыт работы с ansible будет намного лучше, если вы изучите модули и не будете пытаться создать «сценарий оболочки в yaml» — для воссоздания потребовалось 4 строки
- file: path=/var/www state=directory