Vagrantfile setup to allow Ansible to SSH in

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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

VAGRANTFILE_API_VERSION = "2"

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
end

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

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

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


And my Ansible hosts file;



# Application servers
[app]
192.168.60.4
192.168.60.5
# Database servers
[db]
192.168.60.6

# Group 'multi' with all servers
[multi:children]
app
db

# Variables that will be appliedto all servers
[multi:vars]
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key


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







share|improve this question




















  • See vagrantup.com/docs/vagrantfile/ssh_settings.html . config.ssh.port, config.ssh.host and more.
    – Valentin B
    Oct 22 '17 at 9:44










  • I did see them, but I'm unsure of the parameters
    – eekfonky
    Oct 22 '17 at 9:48










  • Here is an example gist.github.com/franciscotfmc/9517513d0e185eca5b2247f17d913004
    – Valentin B
    Oct 22 '17 at 9:52










  • Please note that you are using a key in ansible, and in vagrant you have config.ssh.insert_key=false
    – Rui F Ribeiro
    Oct 22 '17 at 10:11














up vote
0
down vote

favorite












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

VAGRANTFILE_API_VERSION = "2"

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
end

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

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

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


And my Ansible hosts file;



# Application servers
[app]
192.168.60.4
192.168.60.5
# Database servers
[db]
192.168.60.6

# Group 'multi' with all servers
[multi:children]
app
db

# Variables that will be appliedto all servers
[multi:vars]
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key


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







share|improve this question




















  • See vagrantup.com/docs/vagrantfile/ssh_settings.html . config.ssh.port, config.ssh.host and more.
    – Valentin B
    Oct 22 '17 at 9:44










  • I did see them, but I'm unsure of the parameters
    – eekfonky
    Oct 22 '17 at 9:48










  • Here is an example gist.github.com/franciscotfmc/9517513d0e185eca5b2247f17d913004
    – Valentin B
    Oct 22 '17 at 9:52










  • Please note that you are using a key in ansible, and in vagrant you have config.ssh.insert_key=false
    – Rui F Ribeiro
    Oct 22 '17 at 10:11












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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

VAGRANTFILE_API_VERSION = "2"

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
end

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

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

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


And my Ansible hosts file;



# Application servers
[app]
192.168.60.4
192.168.60.5
# Database servers
[db]
192.168.60.6

# Group 'multi' with all servers
[multi:children]
app
db

# Variables that will be appliedto all servers
[multi:vars]
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key


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







share|improve this question












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

VAGRANTFILE_API_VERSION = "2"

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
end

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

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

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


And my Ansible hosts file;



# Application servers
[app]
192.168.60.4
192.168.60.5
# Database servers
[db]
192.168.60.6

# Group 'multi' with all servers
[multi:children]
app
db

# Variables that will be appliedto all servers
[multi:vars]
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key


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









share|improve this question











share|improve this question




share|improve this question










asked Oct 22 '17 at 9:32









eekfonky

172417




172417











  • See vagrantup.com/docs/vagrantfile/ssh_settings.html . config.ssh.port, config.ssh.host and more.
    – Valentin B
    Oct 22 '17 at 9:44










  • I did see them, but I'm unsure of the parameters
    – eekfonky
    Oct 22 '17 at 9:48










  • Here is an example gist.github.com/franciscotfmc/9517513d0e185eca5b2247f17d913004
    – Valentin B
    Oct 22 '17 at 9:52










  • Please note that you are using a key in ansible, and in vagrant you have config.ssh.insert_key=false
    – Rui F Ribeiro
    Oct 22 '17 at 10:11
















  • See vagrantup.com/docs/vagrantfile/ssh_settings.html . config.ssh.port, config.ssh.host and more.
    – Valentin B
    Oct 22 '17 at 9:44










  • I did see them, but I'm unsure of the parameters
    – eekfonky
    Oct 22 '17 at 9:48










  • Here is an example gist.github.com/franciscotfmc/9517513d0e185eca5b2247f17d913004
    – Valentin B
    Oct 22 '17 at 9:52










  • Please note that you are using a key in ansible, and in vagrant you have config.ssh.insert_key=false
    – Rui F Ribeiro
    Oct 22 '17 at 10:11















See vagrantup.com/docs/vagrantfile/ssh_settings.html . config.ssh.port, config.ssh.host and more.
– Valentin B
Oct 22 '17 at 9:44




See vagrantup.com/docs/vagrantfile/ssh_settings.html . config.ssh.port, config.ssh.host and more.
– Valentin B
Oct 22 '17 at 9:44












I did see them, but I'm unsure of the parameters
– eekfonky
Oct 22 '17 at 9:48




I did see them, but I'm unsure of the parameters
– eekfonky
Oct 22 '17 at 9:48












Here is an example gist.github.com/franciscotfmc/9517513d0e185eca5b2247f17d913004
– Valentin B
Oct 22 '17 at 9:52




Here is an example gist.github.com/franciscotfmc/9517513d0e185eca5b2247f17d913004
– Valentin B
Oct 22 '17 at 9:52












Please note that you are using a key in ansible, and in vagrant you have config.ssh.insert_key=false
– Rui F Ribeiro
Oct 22 '17 at 10:11




Please note that you are using a key in ansible, and in vagrant you have config.ssh.insert_key=false
– Rui F Ribeiro
Oct 22 '17 at 10:11










1 Answer
1






active

oldest

votes

















up vote
1
down vote













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






share|improve this answer






















  • 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







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399677%2fvagrantfile-setup-to-allow-ansible-to-ssh-in%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













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






share|improve this answer






















  • 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















up vote
1
down vote













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






share|improve this answer






















  • 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













up vote
1
down vote










up vote
1
down vote









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






share|improve this answer














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







share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 22 '17 at 10:29

























answered Oct 22 '17 at 10:17









Rui F Ribeiro

36.1k1271114




36.1k1271114











  • 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

















  • 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
















I have something like that in the etc/ansible/hosts file
– eekfonky
Oct 22 '17 at 10:21




I have something like that in the etc/ansible/hosts file
– eekfonky
Oct 22 '17 at 10:21




1




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





@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


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399677%2fvagrantfile-setup-to-allow-ansible-to-ssh-in%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)