首页 文章

Ansible远程配置流浪汉

提问于
浏览
-1

我正在使用ansible远程服务器来配置我的 生产环境 服务器,这很好用 . 现在我想到使用这个ansible服务器来配置我的流浪汉 .

这有可能吗?我想到了通过ssh登录到ansible服务器的vagrant文件的shell脚本配置,并对本地机器上的VM执行playbook命令 .

我对shell脚本没有太多经验 . 有没有人试过这个或者可以告诉我一个更好的方法呢?

1 回答

  • 1

    正如Mxx所写,最好的方法是配置Vagrant盒,以便从本地机器使用Ansible配置它 . 然后你只需要键入 vagrant up [name of the box] ,这将启动机器并进行配置 . 下面我附上了一个使用Ansible配置Vagrant框的简单示例,您可以找到有关Ansible provisioner here的所有详细信息 .

    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    
    # Example of vagrant box provisioned using Ansible
    # Start box: "vagrant up dev"
    config.vm.define "dev" do |dev|
      dev.vm.box = "Centos-6.5-minimal-x86_64-20140116"
      dev.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box"
    
      dev.vm.provider :virtualbox do |vb|
        vb.customize [
                        "modifyvm", :id,
                        "--name", "example-vagrant-box",
                        "--memory", 1024,
                        "--cpus", 2,
                    ]
      end
      dev.vm.network :private_network, ip: "10.0.0.1"
      dev.vm.hostname = "vagrant.local"
    
      # Provision the box using Ansible provisioner
      dev.vm.provision "ansible" do |ansible|
        # Path to the inventory file
        ansible.inventory_path = "./inventories/local"
        # Path to playbook that should be run against the machine
        ansible.playbook = "someplaybook.yml"
        # Provisioning verbosity level
        # "v", "vv", "vvv", "vvvv". 4 x v for the most verbose debugging info
        ansible.verbose = "vvvv"
        # Limit provisioning to the following groups
        # This defines all the servers (or server groups) which should be provisioned to
        # These are defined in the inventory file.
        ansible.limit = ["db_servers"]
    
        # Determines whether Ansible ask for Ansible Vault password when provisioner encounter encrypted file
        # ansible.ask_vault_pass = "true"
        # Optionally Ansible Vault password can be stored in the seperate file and passed like this
        ansible.vault_password_file = "./vault-password"
      end
    end
    

相关问题