I have a vagrantfile from a book about Ansible for Devops. The issue I have is that I can SSH into the servers but Ansible cannot. Here is my vagrantfile;

# -*- mode: ruby -*-
# vi: set ft=ruby


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # General Vagrant VM configuration
  config.vm.box = "geerlingguy/centos7"
  config.ssh.insert_key = false
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provider :virtualbox do |v|
    v.memory = 256
    v.linked_clone = true

# Application server 1
  config.vm.define "app1" do |app|
    app.vm.hostname = "orc-app1.dev"
    app.vm.network :private_network, ip: ""

# Application server 2
  config.vm.define "app2" do |app|
    app.vm.hostname = "orc-app2.dev"
    app.vm.network :private_network, ip: ""

# Database server
  config.vm.define "db" do |db|
    db.vm.hostname = "orc-db.dev"
    db.vm.network :private_network, ip: ""

And my Ansible hosts file;

# Application servers
# Database servers

# Group 'multi' with all servers

# Variables that will be appliedto all servers

I know I can explicitly add ansible_ssh_port=2200 etc but I'd rather have it setup in the vagrantfile


You are using an ssh key to authenticate ansible, and as such you configure in vagrant a user with an ssh key, as in:

config.ssh.insert_key = true
config.ssh.username = "deploy-user"
config.ssh.private_key_path = "shared/deploy-user.pem"

I also advise the ssh user not to be root, but a user with sudo capabilities when in a production setting.

The other alternative is to put the ansible user rsa private/public key by hand in a newly provisioned system. The place is ~ansible_user/.ssh/authorized_keys

  • I have something like that in the etc/ansible/hosts file – eekfonky Oct 22 '17 at 10:21
  • 1
    @eekfonky Of course you have, but that is on ansible side. The system being provisioned has to have the SSH ansible public key there for ansible to be able to login. – Rui F Ribeiro Oct 22 '17 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.