Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iriskins/jumpserver_asset
Ansible module for creating or deleting assets
https://github.com/iriskins/jumpserver_asset
ansible ansible-modules automation devops jumpserver
Last synced: 9 days ago
JSON representation
Ansible module for creating or deleting assets
- Host: GitHub
- URL: https://github.com/iriskins/jumpserver_asset
- Owner: iriskins
- Created: 2025-01-31T10:59:11.000Z (11 days ago)
- Default Branch: master
- Last Pushed: 2025-01-31T12:02:03.000Z (11 days ago)
- Last Synced: 2025-01-31T12:30:02.088Z (11 days ago)
- Topics: ansible, ansible-modules, automation, devops, jumpserver
- Language: Python
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Jumpserver Assets Ansible Module
An Ansible module for managing assets (hosts) in JumpServer using its REST API. This module allows you to create or delete assets in your JumpServer instance seamlessly within Ansible playbooks.
## Features
- **Create Assets**: Add new assets to JumpServer with specified parameters (name, address, protocols).
- **Delete Assets**: Remove existing assets by name.
- **Idempotent Operations**: Ensures no duplicate assets are created and handles absent assets gracefully.
- **REST API Integration**: Directly interacts with JumpServer's API for efficient asset management.## Prerequisites
- Ansible installed on the control machine.
- `requests` library installed on the target machine (if not using a module running locally).
- Access to the JumpServer API with a valid API token.
- Proper network connectivity to the JumpServer host.## Installation
1. Place the `jumpserver_assets.py` file in your Ansible project's `library/` directory.
2. Ensure the `requests` library is installed where the module will execute:
```bash
pip install requests
```## Usage
### Module Parameters
| Parameter | Description | Required | Default | Choices |
|------------|-----------------------------------------------------------------------------|----------|---------|-----------------|
| `host` | Hostname/IP of the JumpServer API. | Yes | - | - |
| `api_token`| API token for authentication. | Yes | - | - |
| `name` | Name of the asset. | Yes | - | - |
| `address` | IP address/hostname of the asset (required when `state=present`). | Yes* | - | - |
| `state` | Desired state of the asset. | No | present | `present`, `absent` |*Required when `state=present`.
### Example Playbooks
**Create an Asset**:
```yaml
- name: Ensure asset 'server01' exists
jumpserver_assets:
host: "jumpserver.example.com"
api_token: "your_api_token_here"
name: "server01"
address: "192.168.1.100"
state: present
```**Delete an Asset**:
```yaml
- name: Ensure asset 'server01' is removed
jumpserver_assets:
host: "jumpserver.example.com"
api_token: "your_api_token_here"
name: "server01"
state: absent
```## Return Values
| Key | Description | Type | Example Output |
|-----------|--------------------------------------|--------|------------------------------------------|
| `changed` | Indicates if a change was made. | bool | `true` |
| `msg` | Result message from the operation. | str | "Asset created" or "Asset already exists" |## Contributing
Contributions are welcome! Please fork the repository and submit a pull request.
## Author
@iriskins
---
**Notes**:
- Replace `your_api_token_here` and `jumpserver.example.com` with your actual JumpServer details.
- The module disables SSL verification (`verify=False`). For production, consider enabling SSL and providing a valid certificate.