在Mac OS X上的哪里存储Ansible主机文件 [英] Where to store Ansible host file on Mac OS X

查看:314
本文介绍了在Mac OS X上的哪里存储Ansible主机文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试从Ansible开始配置Vagrantbox,但我不知道如何处理主机文件.

I am trying to get started with Ansible to provision my Vagrantbox, but I can’t figure out how to deal with host files.

根据文档,应该将其存储在/etc/ansible/hosts中,但是在我的系统(Mac OS X)上找不到此文件.我还看到了示例,其中host.ini文件位于文档根目录中,靠近流浪者文件.

According to the documentation the should be storred in /etc/ansible/hosts, but I can’t find this on my system (Mac OS X). I also seen examples where the host.ini file situated in the document root adjacent to the vagrant file.

所以我的问题是,您将在哪里存储用于设置单个无用信息框的主机文件?

So my question is where would you store your hostfile for setting up a single vagrant box?

推荐答案

虽然Ansible默认会尝试/etc/ansible/hosts,但是有几种方法可以告诉ansible在哪里寻找替代清单文件:

While Ansible will try /etc/ansible/hosts by default, there are several ways to tell ansible where to look for an alternate inventory file :

  • 使用-i命令行开关并传递库存文件路径
  • ~/.ansible.cfg 配置文件[defaults]部分中
  • 添加inventory = path_to_hostfile
  • 使用DomaNitro在他的答案中建议的export ANSIBLE_HOSTS=path_to_hostfile
  • use the -i command line switch and pass your inventory file path
  • add inventory = path_to_hostfile in the [defaults] section of your ~/.ansible.cfg configuration file
  • use export ANSIBLE_HOSTS=path_to_hostfile as suggested by DomaNitro in his answer

现在,如果您要使用流浪者中可用的可用的预配服务商,则无需提及,或者如果您想手动配置无业游民的主机.

Now you don't mention if you want to use the ansible provisionner available in vagrant, or if you want to provision your vagrant host manually.

我们先去找Vagrant ansible供应者吧:

Let's go for the Vagrant ansible provisionner first :

创建目录(例如测试),然后在内部创建一个Vagrant文​​件:

Create a directory (e.g. test), and create a Vagrant file inside :

流浪文件:

Vagrant.configure("2") do |config|

  config.vm.box = "precise64-v1.2"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

  config.vm.define :webapp do |webapp|
    webapp.vm.hostname = "webapp.local"
    webapp.vm.network :private_network, ip: "192.168.123.2"
    webapp.vm.provider "virtualbox" do |v|
      v.customize ["modifyvm", :id, "--memory", 200, "--name", "vagrant-docs", "--natdnshostresolver1", "on"]
    end
  end

  # 
  # Provisionning
  #
  config.vm.provision :ansible do |ansible|
    ansible.playbook = "provision.yml"
    ansible.inventory_path = "hosts"
    ansible.sudo = true
    #
    # Use anible.tags if you want to restrict what `vagrant provision`
    # Here is a list of possible tags
    # ansible.tags = "foo bar"
    #
    # Use ansible.verbose to see detailled output for ansible runs
    # ansible.verbose = 'vvv'
    #
    # Customize your stuff here
    ansible.extra_vars = { 
      some_var: 42,
      foo: "bar",
    }
  end
end

现在,当您运行vagrant up(或vagrant provision)时,Vangrant的ansible provnerner将在与Vagrantfile相同的目录中查找文件名hosts,并尝试应用provision.yml剧本.

Now when you run vagrant up (or vagrant provision), Vangrant's ansible provionner will look for a file name hosts in the same directory as Vagrantfile, and will try to apply the provision.yml playbook.

您也可以手动运行它,而无需借助Vagrant的ansible Provisionner:

You can also run it manually, without resorting to Vagrant's ansible provisionner :

ansible-playbook -i hosts provision.yml --ask-pass --sudo

请注意,Vagrant + Virtualbox + Ansible三人并不总是相处融洽.有些版本组合存在问题.如果遇到问题(尤其是关于网络),请尝试升级到最新版本.

Note that Vagrant+Virtualbox+Ansible trio does not always get along well. There are some versions combinations that are problematic. Try to upgrade to the latests versions if you experience issues (especially regarding network).

{shameless_plug},您可以在此处处找到更广泛的示例, a> {/shameless_plug}

{shameless_plug} You can find an more extensive example mixing vagrant and ansible here {/shameless_plug}

祝你好运!

这篇关于在Mac OS X上的哪里存储Ansible主机文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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