Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Added file provisioner to Vagrantfile to copy know_hosts from host to… #234

Merged
merged 1 commit into from
Oct 7, 2015

Conversation

ravbaba
Copy link

@ravbaba ravbaba commented Sep 7, 2015

It copies know_hosts from host to VM so you are avoiding a message which you need to confirm when you are trying to connect first time via ssh with a particular host.

@ravbaba ravbaba mentioned this pull request Sep 7, 2015
@oxyc
Copy link
Collaborator

oxyc commented Sep 8, 2015

Cool 👍

@@ -63,6 +63,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
mount_options: synced_folder.include?('mount_options') ? synced_folder['mount_options'] : []
end

# Provision using file provisioner to add known_hosts from host to guest.
config.vm.provision "file", source: "~/.ssh/known_hosts", destination: "~/.ssh/known_hosts"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work correctly on Windows? I haven't used the file provisioner with a file that may or may not exist, so haven't seen the behavior if the file doesn't exist.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geerlingguy you are right, I haven't test it on Windows and I can guess it won't work on it. I can move it to an ansible task just tell me where you prefer to place it then I can check if the file exists or not.

@geerlingguy
Copy link
Owner

@ravbaba - You could probably do something like the following, maybe inside sshd.yml:

    # Copy over known_hosts.
    - name: Check if known_hosts file is present.
      stat: path=~/.ssh/known_hosts
      register: known_hosts
      connection: local
      sudo: no

    - name: Copy known_hosts file from host into Drupal VM.
      copy:
        src: ~/.ssh/known_hosts
        dest: ~/.ssh/known_hosts
        mode: 0644
      sudo: no
      when: known_hosts.stat.exists

Please see if that works. If so, that's probably a little cleaner, and should work fine on Windows hosts.

@ravbaba
Copy link
Author

ravbaba commented Sep 23, 2015

@geerlingguy - I am going to check it on ios and ubuntu if I find some time today and on Windows but during the weekend. Thank you for the example ;)

@ravbaba ravbaba force-pushed the issue-58 branch 5 times, most recently from 1158ede to 67379dd Compare September 23, 2015 16:05
@ravbaba
Copy link
Author

ravbaba commented Sep 23, 2015

@geerlingguy - I've just tested it on my mac and it works for me, I added some modification to your code so please let me know if you are ok with it. I added your code to my PR.

@ravbaba
Copy link
Author

ravbaba commented Sep 28, 2015

I tested it on ubuntu and it works as well, didn't manage to test it on windows.

@@ -61,6 +61,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provision "ansible" do |ansible|
ansible.playbook = "#{dir}/provisioning/playbook.yml"
ansible.sudo = true
ansible.extra_vars = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This configuration is not needed, as Ansible picks up any configuration from config.yml automatically.

geerlingguy added a commit that referenced this pull request Oct 7, 2015
PR #234: Copy known_hosts from host to VM.
@geerlingguy geerlingguy merged commit ff3ae45 into geerlingguy:master Oct 7, 2015
geerlingguy added a commit that referenced this pull request Oct 7, 2015
@ravbaba
Copy link
Author

ravbaba commented Oct 7, 2015

@geerlingguy - sorry, I've just noticed your comments. Thank you for merging and cleaning up the PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants