Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haidaram/vagrant-to-ansible-inventory
Simple script to transform 'vagrant ssh-config' output to an inventory hosts for Ansible
https://github.com/haidaram/vagrant-to-ansible-inventory
ansible ansible-inventory python-2 python3 vagrant
Last synced: about 2 months ago
JSON representation
Simple script to transform 'vagrant ssh-config' output to an inventory hosts for Ansible
- Host: GitHub
- URL: https://github.com/haidaram/vagrant-to-ansible-inventory
- Owner: haidaraM
- License: mit
- Created: 2017-10-10T12:15:47.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-05T04:43:45.000Z (over 3 years ago)
- Last Synced: 2024-10-12T09:41:32.537Z (2 months ago)
- Topics: ansible, ansible-inventory, python-2, python3, vagrant
- Language: Python
- Size: 31.3 KB
- Stars: 4
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Vagant to Ansible inventory
[![Build Status](https://travis-ci.org/haidaraM/vagranttoansibleinventory.svg?branch=master)](https://travis-ci.org/haidaraM/vagranttoansibleinventory)
[![PyPI version](https://badge.fury.io/py/vagranttoansible.svg)](https://badge.fury.io/py/vagranttoansible)A simple library to convert `vagrant ssh-config` to an inventory file for Ansible.
## Usage
Inside your vagrant directory, run the script `vagrant2ansible` This will create
a filed named `hosts` (your Ansible inventory) in the current directory along with a file named `.vagrant-ssh-config` (the
output of `vagrant ssh-config`).The script has been tested with **Vagrant 2.0** but it should work with earlier versions of Vagrant too.
## Installation
```bash
$ pip install vagranttoansible
```## Example
```bash
$ vagranttoansible
```This configuration:
```yaml
Host machine1
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/mha-dw/Projets/ansible/.vagrant/machines/machine1/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
Host machine2
HostName 127.0.0.1
User vagrant
Port 2200
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/mha-dw/Projets/ansible/.vagrant/machines/machine2/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
```
will be
```ini
machine1 ansible_host=127.0.0.1 ansible_user=vagrant ansible_ssh_common_args='-o StrictHostKeyChecking=no' ansible_ssh_private_key_file=/home/mha-dw/Projets/ansible/.vagrant/machines/machine1/virtualbox/private_key ansible_port=2222
machine2 ansible_host=127.0.0.1 ansible_user=vagrant ansible_ssh_common_args='-o StrictHostKeyChecking=no' ansible_ssh_private_key_file=/home/mha-dw/Projets/ansible/.vagrant/machines/machine2/virtualbox/private_key ansible_port=2200
``````bash
$ vagranttoansible --help
usage: vagranttoansible [-h] [-V] [-v] [-o OUTPUT_FILE_NAME]Simple script to transform 'vagrant ssh-config' output to an inventory hosts
for Ansible. This script must be run in your vagrant folder.optional arguments:
-h, --help show this help message and exit
-V, --version Print version and exits
-v, --verbose Print more information
-o OUTPUT_FILE_NAME, --output-file-name OUTPUT_FILE_NAME
The inventory file name to write hosts to. Default: stdout
```## TODO
- Maybe remove the stormssh dependency
- Test with different Vagrant environmentsMore options will be added. Feel free to contribute.
## Credits
Mohamed El Mouctar HAIDARA ([email protected])