Ansible Configure VM
Configure virtual machines using Ansible playbooks and ad-hoc commands.
Inputs
| Input | Type | Default | Purpose |
|---|---|---|---|
playbook |
string | "" | Path to Ansible playbook |
inventory |
string | "inventory.yaml" | Inventory file path |
hosts |
string | "all" | Target hosts or group pattern |
tags |
string | "" | Ansible tags to run |
check_mode |
bool | false | Dry-run (check) mode |
install_requirements |
bool | false | Install Galaxy requirements first |
Persona
Load infra persona (ansible, ssh tools).
Workflow
1. Bootstrap
persona_load("infra")check_known_issues("ansible", "")— known Ansible issues
2. Environment Check
ansible_version()— Ansible versionansible_config_dump()— configuration
3. Inventory
ansible_inventory_list(inventory=inventory)— list hostsansible_inventory_graph(inventory=inventory)— inventory graphansible_inventory_host(inventory=inventory, host=hosts)— host variables
4. Connectivity
ssh_test(host=hosts)— SSH connectivityansible_ping(host=hosts, inventory=inventory)— Ansible pingansible_setup(host=hosts, inventory=inventory)— gather facts
5. Galaxy (if install_requirements)
ansible_galaxy_list()— installed rolesansible_galaxy_search(query=playbook)— searchansible_galaxy_install(requirements="requirements.yaml")— install
6. Playbook Operations (if playbook provided)
ansible_playbook_list_tasks(playbook=playbook, inventory=inventory)— list tasksansible_playbook_list_tags(playbook=playbook, inventory=inventory)— list tags- If check_mode:
ansible_playbook_check(playbook=playbook, inventory=inventory, limit=hosts, tags=tags) - Else:
ansible_playbook_run(playbook=playbook, inventory=inventory, limit=hosts, tags=tags)
7. Ad-hoc (if no playbook)
ansible_command(host=hosts, inventory=inventory, command="hostname")ansible_shell(host=hosts, inventory=inventory, command="uptime && free -h")
8. Error Handling
- On "unreachable":
learn_tool_fix("ansible_ping", "unreachable", "Host not reachable via SSH", "Check SSH and host is running") - On "permission denied": ensure SSH key authorized or become password
- On "playbook not found": verify playbook path
9. Session Log
memory_session_log("Ansible configure VM", "playbook={playbook}, hosts={hosts}")
Related Skills
vm_lab_setup— create VMs firstmanage_secrets— vault-encrypted vars