All Projects → device42 → Ansible_device42

device42 / Ansible_device42

Licence: other
Scripts to generate static inventory file or generate dynamic inventory for ansible from Device42 data

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Ansible device42

Youtube Videos
Documentation for Techno Tim YouTube Videos
Stars: ✭ 250 (+657.58%)
Mutual labels:  ansible, devops
Semaphore
Modern UI for Ansible
Stars: ✭ 4,588 (+13803.03%)
Mutual labels:  ansible, devops
Baize
白泽自动化运维系统:配置管理、网络探测、资产管理、业务管理、CMDB、CD、DevOps、作业编排、任务编排等功能,未来将添加监控、报警、日志分析、大数据分析等部分内容
Stars: ✭ 296 (+796.97%)
Mutual labels:  ansible, devops
Linchpin
ansible based multicloud orchestrator
Stars: ✭ 107 (+224.24%)
Mutual labels:  inventory, ansible
Ansible For Devops
Ansible for DevOps examples.
Stars: ✭ 5,265 (+15854.55%)
Mutual labels:  ansible, devops
K8s
Deploying Kubernetes High Availability Cluster with Ansible Playbook
Stars: ✭ 125 (+278.79%)
Mutual labels:  inventory, ansible
Ansible For Kubernetes
Ansible and Kubernetes examples from Ansible for Kubernetes Book
Stars: ✭ 389 (+1078.79%)
Mutual labels:  ansible, devops
Helloworld Msa
Main repository with documentation and support files
Stars: ✭ 218 (+560.61%)
Mutual labels:  ansible, devops
Lain
LAIN's main repo
Stars: ✭ 455 (+1278.79%)
Mutual labels:  ansible, devops
Rundeck
Enable Self-Service Operations: Give specific users access to your existing tools, services, and scripts
Stars: ✭ 4,426 (+13312.12%)
Mutual labels:  ansible, devops
Ansible Proxmox Inventory
Proxmox dynamic inventory for Ansible
Stars: ✭ 100 (+203.03%)
Mutual labels:  inventory, ansible
Opscloud
运维管理平台(阿里云),自动同步阿里云配置信息,堡垒机(容器),批量运维,Kubernetes,Zabbix管理等功能
Stars: ✭ 788 (+2287.88%)
Mutual labels:  ansible, devops
Upcloud Ansible
Dynamic inventory and modules for managing servers via UpCloud's API
Stars: ✭ 50 (+51.52%)
Mutual labels:  inventory, ansible
Ansible Cmdb
Ansible-cmdb takes the output of Ansible's fact gathering and converts it into a static HTML overview page (and other things) containing system configuration information.
Stars: ✭ 2,003 (+5969.7%)
Mutual labels:  inventory, ansible
Opendevops
CODO是一款为用户提供企业多混合云、一站式DevOps、自动化运维、完全开源的云管理平台、自动化运维平台
Stars: ✭ 2,990 (+8960.61%)
Mutual labels:  ansible, devops
Devops Guide
DevOps Guide - Development to Production all configurations with basic notes to debug efficiently.
Stars: ✭ 4,119 (+12381.82%)
Mutual labels:  ansible, devops
Werf
The CLI tool gluing Git, Docker, Helm, and Kubernetes with any CI system to implement CI/CD and Giterminism
Stars: ✭ 2,814 (+8427.27%)
Mutual labels:  ansible, devops
Nci Ansible Ui
Simple web interface for running Ansible playbooks
Stars: ✭ 217 (+557.58%)
Mutual labels:  ansible, devops
Tads Boilerplate
Terraform + Ansible + Docker Swarm boilerplate = DevOps on 🔥🔥🔥 | Infrastructure as Code
Stars: ✭ 424 (+1184.85%)
Mutual labels:  ansible, devops
Ios Dev Playbook
不会运维的 iOS 开发不是好设计师。这个 Ansible Playbook 能快速配置 iOS 开发需要的服务,安装如 Gogs、GitLab、Jenkins、Ghost、Ajenti 等常用服务。
Stars: ✭ 542 (+1542.42%)
Mutual labels:  ansible, devops

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 Ansible Collection contains the inventory and lookup plugins for Device42.

  1. Inventory (device42.d42.d42) - can be used to dynamically generate Ansible inventory from Device42 devices.
  2. Lookup (device42.d42.d42)- This lookup plugin allows a playbook to fetch passwords or ip addresses for hosts from Device42.
  3. Lookup (device42.d42.d42_prompt) - This lookup plugin allows a playbook to fetch passwords or ip addresses for hosts from Device42 with prompt.

In the contrib directory you will find the legacy inventory scripts. Please favor the plugin over the legacy scripts:

  1. contrib\inventory\d42_ansible_inventory_hostfile.py 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. contrib\inventory\d42_ansible_dynamic_inventory.py can be used to dynamically by ansible to get hosts from Device42 based on certain filters.

Requirements

  • ansible 2.9+
  • python 3.6.x+
  • Device42 16.12.00+
  • requests (you can install it with pip install requests or apt-get install python-requests)
  • Ansible must have an available connection to your Device42 instance in order to collect devices for inventory

Installation Methods

Galaxy

ansible-galaxy collection install device42.d42

Automation Hub

To consume content from hub as part of your automation workflows the content can also be accessed via CLI. For this an offline token is required which can be obtained via the web UI at automation hub, and needs to be added to the configuration file as follows:

[galaxy]
server_list = automation_hub, galaxy

[galaxy_server.automation_hub]
url=https://cloud.redhat.com/api/automation-hub/
auth_url=https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
token=AABBccddeeff112233gghh...

[galaxy_server.galaxy]
url=https://galaxy.ansible.com/

Once configured the collection can be installed by running the following command

$ ansible-galaxy collection install device42.d42

Ansible Tower:

  • Create a collections requirement file in the SCM
touch requirements.yml
  • add the following to your file and save it
collections:
- name: device42.d42
version: 1.1.2
source: https://galaxy.ansible.com/

* Install the Ansible collection by running command
```bash
ansible-galaxy collection install -r requirements.yml -p <job tmp location>

Starting with Ansible Tower 3.6, the project folder will be copied for each job run. This allows playbooks to make local changes to the source tree for convenience, such as creating temporary files, without the possibility of interference with other jobs.

  • Set the following environmental variables (optional)
D42_USER = 'device42 user'
D42_PWD = 'device42 password'
D42_URL = 'https:// device42 server IP address'
D42_SKIP_SSL_CHECK = False
D42_CLEAN_DEVICE_NAME = True

For more information on installing collections please follow documentation here https://docs.ansible.com/ansible/latest/user_guide/collections_using.html


Inventory Plugin

Configuration

Define an inventory file (*.d42.yml)

View documentation using ansible-doc -t inventory device42.d42.d42

Environmental variables not defined:

plugin: device42.d42.d42
url: https://10.10.10.10
username: admin
password: password
ssl_check: False
debug: False
clean_device_name: True
keyed_groups:
    - key: d42_service_level
      prefix: ''
      separator: ''

Environmental variables defined:

plugin: device42.d42.d42
keyed_groups:
    - key: d42_service_level
      prefix: ''
      separator: ''

See Ansible documentation for more constructed examples.

How to run

from the directory of your newly created file run the following command.

ansible-inventory -i *.d42.yml --graph

Lookup Plugin

Configuration

If using environmental variables skip this step, if not create a d42.py or d42_prompt.py in ansible/lib/ansible/plugins/lookup/ with the following information

D42_USER = 'device42 user'
D42_PWD = 'device42 password'
D42_URL = 'https:// device42 server IP address'
D42_SKIP_SSL_CHECK = False
D42_DEBUG = False
D42_CLEAN_DEVICE_NAME = True

How to run

To get password call: lookup('d42', 'device_name', 'password', 'username')

device_name and username need to be filled in

To run any doql request: lookup('d42', 'SELECT ... FROM ...', 'doql', 'list')

doql query need to be filled in + we need to set data type of returned result ( 'string', 'list', 'list_dicts' )

  • string - return single string without column headers
  • list - return list of string ( we split DOQL result line by line without column headers )
  • list_dicts - return list of dicts with column headers

All above works the same for the prompt version, we just add 3 more arguments in the yaml file, please check reference in promt example.

The following was tested in a playbook using the included example template example_playbook.yaml playbooks can be run by using the following command

ansible-playbook *.yaml -f 10

Legacy Inventory Usage


Requirements

  • ansible 2.9+

  • python 3.6.x+ or python 2.7.x

  • Device42 16.12.00+

  • requests (you can install it with pip install requests or apt-get install python-requests)

  • Ansible must have an available connection to your Device42 instance in order to collect devices for inventory

    • rename conf.sample.ini to conf.ini
    • in conf add D42 URL/credentials ( also instead of conf file, possible to use environment variables )
# ====== Device42 upload settings =========
[DEFAULT]
D42_USER = admin
D42_PWD = adm!nd42
D42_URL = https://10.10.10.10
D42_SKIP_SSL_CHECK = True
D42_DEBUG = FALSE

# ====== Ansible settings =========
[DOQL]
GROUP_BY_QUERY = select name, service_level from view_device_v1
GROUP_BY_FIELD = service_level
GROUP_BY_REFERENCE_FIELD = name
SPLIT_GROUP_BY_COMMA = False

Navigate to the root folder of the script .../ansible_device42

Run the python -m contrib.inventory.d42_ansible_inventory_hostfile and enjoy!

Also you may use automatic version with Ansible commands ex.

ping :

ansible all -i d42_ansible_dynamic_inventory.py -m ping

copy ssh file :

ansible all -i d42_ansible_dynamic_inventory.py -m authorized_key -a "user=root key='ssh-rsa AAAA...XXX == [email protected]'"

modify file :

ansible all -i d42_ansible_dynamic_inventory.py -m lineinfile -a "dest=/etc/group regexp='^(users❌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 device42.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].