Windows上带有游标的多机ansible设置 [英] Multi-machine ansible setup with vagrant on windows

查看:64
本文介绍了Windows上带有游标的多机ansible设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望Ansible [通过Vagrant]在Windows 8机器上配置虚拟盒虚拟机.一切都需要在本地运行,并且由于Ansible不能在Windows上运行,因此我以ansible作为控制机引导了一个debian vm. 此代码作为示例. 在使用该系统后,我得到了一些工作,但并不能完全解决问题(尽管ansible不能告诉我).

I want ansible to provision virtual box vm's on my windows 8 machine [via Vagrant]. Everything needs to run locally and since Ansible doesn't run on Windows, I bootstrap a debian vm with ansible as the control machine. This code served as an example. After struggling with the system I got it somewhat working, but not completely (although ansible doesn't tell me).

如果需要,使用ansible [在vm中],vagrant和virtualbox [在Windows主机上]进行多计算机设置需要什么配置:

  1. ssh从主机访问ansible-vm以及所有从属服务器

  1. ssh acces from the host machine to the ansible-vm as well as all the slaves

ssh从ansible-vm访问所有从属服务器

ssh acces from the ansible-vm to all the slaves

能够在可能的情况下将多计算机网络与主机网络隔离

being able to shield the multi-machine network from the host's network, if possible

问题

运行ansible -m ping -all -i path-to-hosts会产生ssh错误.似乎很可能尝试访问名为web1和db1的计算机,但找不到此类主机.

Problem

Running ansible -m ping -all -i path-to-hosts yields ssh errors. It seems ansible tries to reach the machines named web1 and db1, but can't find such hosts.

与用户建立连接:无业游民 REMOTE_MODULE ping 为用户建立连接:vagrant REMOTE_MODULE ping EXEC ['ssh','-C','-tt','-vvv','-o','ControlMaster = auto','-o','ControlPersist = 60s','-o','ControlPath =/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r','-o','KbdInteractiveAuthentication = no','-o','PreferredAuthentications = gssapi-with-mic, gssapi-keyex,基于主机,公钥",-o","PasswordAuthentication = no",-o","ConnectTimeout = 10","web1","/bin/sh -c'mkdir -p $ HOME/. ansible/tmp/ansible-tmp-1398362619.41-142470238612762& chmod a + rx $ HOME/.ansible/tmp/ansible-tmp-1398362619.41-142470238612762&& echo $ HOME/.ansible/tmp/ansible-tmp -1398362619.41-142470238612762'] 找不到适用于web1的EXEC先前已知的主机文件 EXEC ['ssh','-C','-tt','-vvv','-o','ControlMaster = auto','-o','ControlPersist = 60s','-o','ControlPath =/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r','-o','KbdInteractiveAuthentication = no','-o','PreferredAuthentications = gssapi-with-mic, gssapi-keyex,基于主机,公钥",-o","PasswordAuthentication = no",-o","ConnectTimeout = 10","db1","/bin/sh -c'mkdir -p $ HOME/. ansible/tmp/ansible-tmp-1398362619.41-4982781019922& chmod a + rx $ HOME/.ansible/tmp/ansible-tmp-1398362619.41-4982781019922&& echo $ HOME/.ansible/tmp/ansible-tmp -1398362619.41-4982781019922'] 找不到db1的EXEC先前的已知主机文件 web1 | FAILED => SSH遇到未知错误.输出为: OpenSSH_6.0p1 Debian-4,OpenSSL 1.0.1e 2013年2月11日 debug1:读取配置数据/etc/ssh/ssh_config debug1:/etc/ssh/ssh_config第19行:为*应用选项 debug1:auto-mux:尝试现有的母版 debug1:控制套接字"/home/vagrant/.ansible/cp/ansible-ssh-web1-22-vagrant"不存在 debug2:ssh_connect:needpriv 0 ssh:无法解析主机名web1:名称或服务未知

ESTABLISH CONNECTION FOR USER: vagrant REMOTE_MODULE ping ESTABLISH CONNECTION FOR USER: vagrant REMOTE_MODULE ping EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', 'web1', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1398362619.41-142470238612762 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1398362619.41-142470238612762 && echo $HOME/.ansible/tmp/ansible-tmp-1398362619.41-142470238612762'"] EXEC previous known host file not found for web1 EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', 'db1', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1398362619.41-4982781019922 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1398362619.41-4982781019922 && echo $HOME/.ansible/tmp/ansible-tmp-1398362619.41-4982781019922'"] EXEC previous known host file not found for db1 web1 | FAILED => SSH encountered an unknown error. The output was: OpenSSH_6.0p1 Debian-4, OpenSSL 1.0.1e 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: auto-mux: Trying existing master debug1: Control socket "/home/vagrant/.ansible/cp/ansible-ssh-web1-22-vagrant" does not exist debug2: ssh_connect: needpriv 0 ssh: Could not resolve hostname web1: Name or service not known

db1 | FAILED => SSH遇到未知错误.输出为: OpenSSH_6.0p1 Debian-4,OpenSSL 1.0.1e 2013年2月11日 debug1:读取配置数据/etc/ssh/ssh_config debug1:/etc/ssh/ssh_config第19行:为*应用选项 debug1:auto-mux:尝试现有的母版 debug1:控制套接字"/home/vagrant/.ansible/cp/ansible-ssh-db1-22-vagrant"不存在 debug2:ssh_connect:needpriv 0 ssh:无法解析主机名db1:名称或服务未知

db1 | FAILED => SSH encountered an unknown error. The output was: OpenSSH_6.0p1 Debian-4, OpenSSL 1.0.1e 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: auto-mux: Trying existing master debug1: Control socket "/home/vagrant/.ansible/cp/ansible-ssh-db1-22-vagrant" does not exist debug2: ssh_connect: needpriv 0 ssh: Could not resolve hostname db1: Name or service not known

代码

以下代码尝试设置 1. ansible-master:控制机器运行的ansible 1. db1:数据库服务器 1. web1:Web服务器

Code

The following code tries to provision 1. ansible-master: the control machine running ansible 1. db1: a database server 1. web1: a web server

Vagrant.configure("2") do |config|
  config.vm.box = "wheezy64"
  config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210.box"
  config.vm.synced_folder ".", "/vagrant", :mount_options => ['dmode=777','fmode=666']

  config.vm.network :public_network

  config.vm.provider "virtualbox" do |v|
      v.customize [
          "modifyvm", :id,
          "--groups", "/Vagrant/Ansible",
         # "--natdnshostresolver1", "on"
      ]
  end

  config.vm.define :ansiblemaster do |ansiblemaster|
   # ansiblemaster.vm.network :private_network, ip: "192.168.111.101"
   ansiblemaster.vm.hostname = "ansiblemaster"
   # ansiblemaster.vm.network :forwarded_port, guest: 80, host: 8080
    ansiblemaster.ssh.forward_agent = true


    ansiblemaster.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", 512]
      vb.customize ["modifyvm", :id, "--name", "ansible-master"]
      vb.name = "ansiblemaster"
    end

    ansiblemaster.vm.provision :shell, :inline =>
      "if [[ ! -f /apt-get-run ]]; then sudo apt-get update && sudo touch /apt-get-run; fi"



    ansiblemaster.vm.provision :shell do |sh|
      sh.path = "provision.sh"
      sh.args = "./ansible provisioning/site.yml provisioning/hosts/dev_hosts"
    end
  end

  config.vm.define :web1 do |slave|
   slave.vm.hostname = "web1"
   # slave.vm.network :private_network, ip: "192.168.111.201"
    slave.vm.synced_folder "./src", "/var/www/site", id: "proj-root"
    slave.vm.provider :virtualbox do |vb|
      vb.name = "web1"
      vb.customize ["modifyvm", :id, "--memory", "512"]
    end
  end

  config.vm.define :db1 do |slave|
    slave.vm.hostname = "db1"
    #slave.vm.network :private_network, ip: "192.168.111.202"
    slave.vm.provider :virtualbox do |vb|
      vb.name = "db1"
      vb.customize ["modifyvm", :id, "--memory", "512"]
    end
  end
end

Provision.sh

#!/bin/bash

ANSIBLE_DIR=$1
ANSIBLE_PLAYBOOK=$2
ANSIBLE_HOSTS=$3
TEMP_HOSTS="/tmp/ansible_hosts"

if [ ! -f /vagrant/$ANSIBLE_PLAYBOOK ]; then
  echo "Cannot find Ansible playbook"
  exit 1
fi

if [ ! -f /vagrant/$ANSIBLE_HOSTS ]; then
  echo "Cannot find Ansible hosts"
  exit 2
fi

if [ ! -d $ANSIBLE_DIR ]; then
  echo "Updating apt cache"
  apt-get update
  echo "Installing Ansible dependencies and Git"
  apt-get install -y git python-yaml python-paramiko python-jinja2
  echo "Cloning Ansible"
  git clone git://github.com/ansible/ansible.git ${ANSIBLE_DIR}
fi

cd ${ANSIBLE_DIR}
cp /vagrant/${ANSIBLE_HOSTS} ${TEMP_HOSTS} && chmod -x ${TEMP_HOSTS}
echo "Running Ansible"
echo "dir is nu: " $(pwd)

source hacking/env-setup
echo "source ${ANSIBLE_DIR}/hacking/env-setup" >> /home/vagrant/.bashrc
ansible-playbook /vagrant/${ANSIBLE_PLAYBOOK} --inventory-file=${TEMP_HOSTS} --connection=local

rm ${TEMP_HOSTS}

provinging/hosts/dev_hosts

[webservers]
web1

[dbservers]
db1

推荐答案

要回答我自己的问题:通过升级ansible并在Provision.sh中导入其他计算机的ssh密钥,可以解决此问题.

To answer my own question: the problem was resolved by upgrading ansible and importing the ssh keys of the other machines in Provision.sh.

# fix permissions on private key file
chmod 600 /home/vagrant/.ssh/id_rsa

# add web/database hosts to known_hosts (IP is defined in Vagrantfile)
ssh-keyscan -H 192.168.51.4 >> /home/vagrant/.ssh/known_hosts
ssh-keyscan -H 192.168.52.4 >> /home/vagrant/.ssh/known_hosts
chown vagrant:vagrant /home/vagrant/.ssh/known_hosts

# reload ssh in order to load the known hosts
/etc/init.d/ssh reload

这篇关于Windows上带有游标的多机ansible设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆