ansible-rs 1.1.0

A Rust wrapper library for Ansible command-line tools (Linux/Unix only)
Documentation
use ansible::{Playbook, Play, Result};

fn main() -> Result<()> {
    // Create and configure Playbook instance
    let mut playbook = Playbook::default();
    playbook.set_inventory("./hosts");

    println!("Playbook command: {}", playbook);

    // Example 1: Run playbook from string content
    println!("\n=== Playbook from String ===");
    let playbook_content = r#"
---
- hosts: all
  gather_facts: yes
  tasks:
    - name: Display system information
      debug:
        msg: "Running on {{ inventory_hostname }} with OS {{ ansible_os_family }}"

    - name: Check disk usage
      shell: df -h /
      register: disk_usage

    - name: Show disk usage
      debug:
        var: disk_usage.stdout_lines
"#;

    match playbook.run(Play::from_content(playbook_content)) {
        Ok(result) => println!("Playbook execution result:\n{}", result),
        Err(e) => println!("Playbook execution failed: {}", e),
    }

    // Example 2: Run playbook from file
    println!("\n=== Playbook from File ===");
    match playbook.run(Play::from_file("playbook.yaml")) {
        Ok(result) => println!("File playbook result:\n{}", result),
        Err(e) => println!("File playbook failed: {}", e),
    }

    // Example 3: Advanced playbook with variables
    println!("\n=== Advanced Playbook ===");
    let advanced_playbook = r#"
---
- hosts: all
  vars:
    greeting: "Hello from Rust Ansible wrapper!"
    packages:
      - curl
      - wget
      - htop
  tasks:
    - name: Display greeting
      debug:
        msg: "{{ greeting }}"

    - name: Show available packages
      debug:
        msg: "Package: {{ item }}"
      loop: "{{ packages }}"

    - name: Get system uptime
      command: uptime
      register: uptime_result
      changed_when: false

    - name: Display uptime
      debug:
        msg: "System uptime: {{ uptime_result.stdout }}"
"#;

    match playbook.run(Play::from_content(advanced_playbook)) {
        Ok(result) => println!("Advanced playbook result:\n{}", result),
        Err(e) => println!("Advanced playbook failed: {}", e),
    }

    Ok(())
}