GithubHelp home page GithubHelp logo

optionalg / ansible-vmware Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raymiiorg/ansible-vmware

0.0 1.0 0.0 4 KB

Simple python script which uses PySphere to fill the Ansible inventory from VMWare vCenter.

Python 100.00%

ansible-vmware's Introduction

Ansible Inventory from VMWare

Simple python script which uses PySphere to fill the Ansible inventory from VMWare vCenter. Originally Cloned from: Github repository = Official Website

My fork has added an option to override the strict SSL Cert Validation: https://www.python.org/dev/peps/pep-0476/ as well as command line option parsing with argparse.

Installation

Install PySphere:

pip install -U pysphere

Edit the script's login data and VCenter server FQDN:

server_fqdn = "vcenter.example.org"
server_username = "jdoe"
server_password = "secure_passw0rd"

Test it:

Get all powered on VM's:

python2 query.py --list

Output:

{
    "no_group": {
        "hosts": [
            "vm0031",
            "vm0032",
            [...]
            "vm0999"
        ]
    },
    "local": [
        "127.0.0.1"
    ]
}

Get one VM:

python2 query.py --host vm0032

Output:

{
    "admin": "[email protected]",
    "source_database": "VMWare"
}

Nonexistent VM:

python2 query.py --host nonexist

Output:

[Error]: [Object Not Found]: Could not find a VM named 'notexist'

Do a simple ansible ping:

ANSIBLE_HOSTS="/home/remy/git/vmware-ansible/query.py" ansible all -m ping

Result:

vm0032 | success >> {
    "changed": false,
    "ping": "pong"
}

vm0034 | success >> {
    "changed": false,
    "ping": "pong"
}

Usage

Either export the ANSIBLE_HOSTS variable to always use the VMWare inventory:

export ANSIBLE_HOSTS="/home/remy/git/vmware-ansible/query.py"

Or preface each ansible command:

ANSIBLE_HOSTS="/home/remy/git/vmware-ansible/query.py" ansible all -m apt -a "upgrade=safe"

Notes

Tested with both vCenter 5.1 and 5.5, Python 2.

Does not support grouping by datacenter or resource group

Thanks to JP Mens's article for the inspiration.

ansible-vmware's People

Contributors

blutgens avatar raymiiorg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.