Profile Conversion
Convert Ruby-based InSpec compliance profiles into Ansible collections for native integration with Ansible workflows.
Overview
The ansible-inspec convert command transforms InSpec profiles into Ansible collections, providing:
Native Ansible tasks for common compliance checks
Automatic role generation from control files
Custom resource support via InSpec wrapper
Ready-to-use playbooks for immediate deployment
Ansible Galaxy compatibility for distribution
Quick Start
# Convert an InSpec profile
ansible-inspec convert /path/to/inspec-profile \
--output-dir ./collections \
--namespace myorg \
--collection-name compliance_baseline
# Build and install the collection
cd collections/ansible_collections/myorg/compliance_baseline
ansible-galaxy collection build
ansible-galaxy collection install myorg-compliance_baseline-*.tar.gz
# Use the collection
ansible-playbook myorg.compliance_baseline.compliance_check -i inventory.ymlCommand Reference
Basic Usage
Options
profile
Path to InSpec profile directory
Required
-o, --output-dir
Output directory for collection
./collections
--namespace
Ansible Galaxy namespace
compliance
--collection-name
Collection name
inspec_profiles
--native-only
Only use native Ansible modules
False
--no-roles
Skip role creation
False
--no-playbooks
Skip playbook creation
False
Examples
Convert DevSec Linux Baseline
Convert Custom Profile
Convert with Native Modules Only
Conversion Process
1. Profile Analysis
The converter analyzes your InSpec profile:
2. Resource Mapping
InSpec resources are mapped to Ansible modules:
file
ansible.builtin.stat
Native
service
ansible.builtin.service_facts
Native
package
ansible.builtin.package_facts
Native
sshd_config
ansible.builtin.lineinfile
Native
command
ansible.builtin.command
Native
port
ansible.builtin.wait_for
Native
kernel_parameter
ansible.posix.sysctl
Native
Custom resources
InSpec wrapper
Wrapper
3. Collection Generation
Creates Ansible collection structure:
Conversion Examples
Example 1: SSH Configuration
InSpec Control (controls/sshd.rb):
Converted Ansible Role (roles/sshd/tasks/main.yml):
Example 2: Service Checks
InSpec Control:
Converted Ansible Tasks:
Example 3: Package Checks
InSpec Control:
Converted Ansible Tasks:
Custom Resources Support
How It Works
Custom InSpec resources from libraries/ directory are:
Detected during conversion
Copied to
files/libraries/in the collectionWrapped in InSpec execution tasks
Documented in
docs/CUSTOM_RESOURCES.md
Example: Custom Resource
InSpec Custom Resource (libraries/example_config.rb):
InSpec Control Using Custom Resource:
Converted Ansible Task:
Requirements for Custom Resources
When your collection uses custom resources:
InSpec must be installed on target or control node
Custom resource files are bundled in the collection
INSPEC_LOAD_PATH environment variable is set automatically
Using Converted Collections
Installation
Running Compliance Checks
Using Roles
Using Included Playbook
Selective Tag Execution
Best Practices
1. Profile Organization
Organize InSpec profiles before conversion:
2. Namespace Selection
Choose meaningful namespaces:
3. Collection Naming
Use descriptive collection names:
4. Version Control
Maintain both profiles and collections:
5. Testing
Test converted collections before deployment:
Troubleshooting
Conversion Fails
Problem: "Invalid InSpec profile"
Solution: Ensure profile has inspec.yml or controls/ directory:
Custom Resources Not Working
Problem: Custom resource checks fail
Solution: Verify InSpec is installed and in PATH:
Role Tasks Not Generated
Problem: Roles created but tasks empty
Solution: Check control file syntax:
Ansible Module Not Found
Problem: Module not found errors when running playbook
Solution: Install required collections:
Advanced Usage
Custom Collection Structure
Modify converted collection before building:
Integration with CI/CD
Publishing to Galaxy
Resources
Support
For issues with profile conversion:
Check GitHub Issues
Review Examples
License
GPL-3.0-or-later
Generated by ansible-inspec - https://github.com/Htunn/ansible-inspec
Last updated