Skip to content

Instantly share code, notes, and snippets.

@momota
Last active July 19, 2017 07:31
Show Gist options
  • Save momota/d51f2908b6bc19cf3cb0431b06d1ef9d to your computer and use it in GitHub Desktop.
Save momota/d51f2908b6bc19cf3cb0431b06d1ef9d to your computer and use it in GitHub Desktop.

Ansible

Inventory

Create inventory file ./hosts as below.

[some-servers]
10.1.1.1 # IP address or hostname

SSH

Setting ssh configuration as below.

$ vagrant ssh-config > ssh.config

Edit ssh.config as below.

- Host HOSTNAME_OF_YOUR_VM
+ Host IP_ADDRESSS
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/momota/dev/ocr/mysql/.vagrant/machines/db01/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

Create ansible configure file ./ansible.cfg.

[defaluts]
hostfile = hosts

[ssh_connection]
ssh_args = -F ssh.config

access

Try access to the vagrant host by using ansible.

$ ansible all -m ping
# You don't need type all options
# =>$ ansible -i hosts all -m ping -u vagrant --private-key=.vagrant/machines/YOUR_HOST/virtualbox/private_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment