SSH does not work due to key file permissions when I try to provide Vagrant VM with Ansible on Windows / Cygwin

Im using Cygwin (CYGWIN_NT-6.3-WOW64) under Windows 8. I also run Vagrant (1.7.2) and Ansible (1.8.4). To be complete, my Virtualbox is 4.3.22.

Cygwin and Vagrant were installed from their respective Windows installation packages. Im running Python 2.7.8 under Cygwin and using 'pip install ansible to install Ansible.

All of these applications work great on their own. Cygwin works great; I use it as my shell all day, every day without any problems.

Vagrant and Virtualbox also work without problems when I run Vagrant under Cygwin. Ansible works great under Cygwin when I run games or modules against servers on my network.

The problem I am facing is that I am trying to use Ansible to make Vagrant VM work locally.

For example, I vagrant up virtual machine, and then create a simple book to play it. Below is the Vagrantfile:

 VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.define :drupal1 do |config| config.vm.box = "centos65-x86_64-updated" config.vm.hostname = "drupal1" config.vm.network "forwarded_port", guest: 80, host: 10080 config.vm.network :private_network, ip: "192.168.56.101" config.vm.provider "virtualbox" do |v| v.name = "Drupal Server 1" v.memory = 1024 end config.vm.provision :ansible do |ansible| ansible.playbook = "provisioning/gather_facts.yml" end end 

and playbook:

 --- - hosts: all gather_facts: yes 

However, when I run the "abusive drupal1 provisioning", I get the following error:

brokerage software drupal1 ==> drupal1: Launching the creator: ansible ... PYTHONUNBUFFERED = 1 ANSIBLE_FORCE_COLOR = true ANSIBLE_HOST_KEY_CHECKING = false ANSIBLE_SSH_ARGS = '- o UserKnownHostsFile = / devMaster-null-auto-script 60 private key = C: /Users/mjenkins/workspace/Vagrant_VMs/Drupal1/.vagrant/machines/drupal1/virtualbox/private_key --user = vagrant --connection = ssh --limit = 'drupal1' --inventory-file = C : /Users/mjenkins/workspace/Vagrant_VMs/Drupal1/.vagrant/provisioners/ansible/inventory provisioning / gather_facts.yml PLAY [all] COMMON FACTS fatal: [drupal1] => private_key_file (C: / Users / mjenkins / workVs / vagrant /Drupal1/.vagrant/machines/drupal1/virtualbox/private_key) is read in groups or read in the world and is therefore unsafe - you will probably get SSH failure. PLAY RECAP

to try again, use: -limit @ / home / mjenkins / gather_facts.retry

drupal1: ok = 0 changed = 0 unreachable = 1
failed = 0 Ansible failed to complete successfully. Any output errors should be visible above. Correct these errors and try again. Looking at the error, it is obvious that she has something to do with the Ansibles interpretation of my key and the permissions for either it or the folder in which it is located.

Here are some notes and steps I tried:

  • I tried to set permissions for the file and all directories leading to the file in Cygwin. This is chmod -R 700 .vagrant in the project directory. There was still the same error.

  • The key file is referenced using the Windows path and not the Cygwin path (it is odd, however, that the file in the terminal output has the Cygwin path). So I checked the permissions on the Windows side and changed them so that "everyone does not have access to .vagrant and all the files / folders under it. Still the same error.

  • Then I thought that there might still be problems with file permissions / paths between my Ansible based on Cygwin, so I installed Python for Windows; used this item to install Ansible, installed my paths to this place, created the ansible-playbook.bat file and launched Vagrant from the windows shell. Glad to say that the tool chain worked ... but I still had the same problem.

At this point, I'm just out of ideas, so I appeal to you, friends of Stackoverflow, for your input.

Any thoughts on solving this problem?

+5
source share
5 answers

BAAAH! I just commented on the check in lib / ansible / runner / connection.py

Then I had to add ansible.cfg [ssh_connection] control_path = /tmp

+3
source

Your private key is very open and accessible to anyone. Verification in the SSH client prevents the use of such keys.

Try changing permissions using chmod from your cygwin or git bash to your private and public keys. In C:/Users/mjenkins/workspace/Vagrant_VMs/Drupal1/.vagrant/machines/drupal1/virtualbox/private_key with chmod 700 private_key and make sure you have -rwx------ with ls -la

+2
source

I had a similar problem and worked out a solution. I added the following entries in my roaming file

 config.ssh.insert_key = false config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key" 

and copied insecure_private_key from my user windows folder to cygwin home as the path above. after that i did

 chmod 700 ~/.vagrant.d/insecure_private_key 

and as a last step I deleted the contents of this file in cygwin house

 ~/.ssh/known_hosts 

As soon as I restart the ansible-playbook command, I confirmed that my local host returned to known_hosts and the ssh connection was working.

0
source

to really say that it’s a lot easier if you understand what’s going on.

  • A tramp holds one folder for exchanging files with the host and another virtual machine, that is, a tramp. Everything that in this case will have mode 777 cannot be done for this. sudo chmod won't help either, and you can't change the mode.

  • Ansible asks you to reduce the mode so that it is not read by the group or all

so it’s as simple as making a copy of the private key from /vagrant/.vagrant/machines/yourmachine/virtualbox or any security tool / maybe at home ie ~ or / root

and then change chmod to 700 and use it in the inventory list in the hosts file.

0
source

My solution was to override the permission settings for synchronized folders in VagrantFile with the following:

 Vagrant.configure(2) do |config| config.vm.synced_folder "./", "/vagrant", owner: "vagrant", mount_options: ["dmode=775,fmode=600"] ... 
0
source

Source: https://habr.com/ru/post/1215261/


All Articles