Skip to content
Scripts to generate static inventory file or generate dynamic inventory for ansible from Device42 data
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Fix ".gitignore" Mar 17, 2017
LICENSE First commit Jan 3, 2017 Add "SPLIT_GROUP_BY_COMMA" feature Sep 2, 2018
conf.sample Add "SPLIT_GROUP_BY_COMMA" feature Sep 2, 2018 Add ability to use global environment variables as settings Jun 20, 2018 encode DOQL response in "UTF-8" Jan 24, 2019

Device42 is a Continuous Discovery software for your IT Infrastructure. It helps you automatically maintain an up-to-date inventory of your physical, virtual, and cloud servers and containers, network components, software/services/applications, and their inter-relationships and inter-dependencies.

This repository has 2 different scripts that you can use with ansible.

  1. can be used to create a static inventory file for ansible. You can group hosts by tags, customers, building or service level from Device42 data.
  2. can be used to dynamically by ansible to get hosts from Device42 based on certain filters.


* This script works with Device42 12.0.0 and above


* python 2.7.x
* requests (you can install it with pip install requests or apt-get install python-requests)


* rename conf.sample to conf
* in conf add D42 URL/credentials ( also instead of conf file, possible to use environment variables )
# ====== Device42 upload settings ========= #
D42_USER = 'device42 user'
D42_PWD = 'device42 password'
D42_URL = 'https:// device42 server IP address'
* in conf add DOQL group settings
# ====== Ansible settings ========= #
GROUP_BY_QUERY = 'select name, service_level from view_device_v1' # DOQL QUERY, POSSIBLE TO GROUP BY ANY FIELD
GROUP_BY_FIELD = 'service_level' # GROUP BY FIELD

Run the python and enjoy!

Also you may use automatic version with Ansible commands ex.

ping :

ansible all -i -m ping

copy ssh file :

ansible all -i -m authorized_key -a "user=root key='ssh-rsa AAAA...XXX == root@hostname'"

modify file :

ansible all -i -m lineinfile -a "dest=/etc/group regexp='^(users:x:100:)(.*)' line='\1ldapusername,\2' state=present backrefs=yes"

and much more! Please read Ansible docs.

If you have any questions - feel free to reach out to us at support at


* Script runs on Linux and Windows
You can’t perform that action at this time.