Project 5: Dynamic Inventory Cloud Fleet

Discover and group ephemeral cloud hosts automatically from provider metadata.

Quick Reference

Attribute Value
Difficulty Level 3
Time Estimate 14-22 hours
Main Programming Language YAML (inventory plugin config)
Coolness Level 3
Business Potential 3. Service & Support
Prerequisites P01, P04
Key Topics Dynamic inventory plugins, tag grouping, cloud targeting

1. Learning Objectives

  1. Configure a dynamic inventory plugin.
  2. Use tags to generate predictable host groups.
  3. Validate discovered hosts before applying changes.
  4. Handle API and cache-related discovery edge cases.

2. All Theory Needed (Per-Concept Breakdown)

2.1 Inventory in Ephemeral Environments

Fundamentals Static host files break down when hosts are short-lived. Dynamic inventory pulls current host sets from provider APIs.

Deep Dive into the concept The core risk shifts from stale static files to metadata quality and API consistency. Tag governance becomes an operational dependency. Plugin filters and keyed groups must be explicit to avoid broad accidental targeting.

Mental model diagram

cloud API -> inventory plugin -> host groups by tags -> playbook targeting

Where you’ll apply it P05, P07, capstone.


3. Project Specification

3.1 What You Will Build

A plugin-based inventory that:

  • discovers running instances
  • groups them by env and role tags
  • supports web-tier target runs with no static host edits

3.2 Functional Requirements

  1. Inventory graph lists expected groups.
  2. tag_role_web group targets only web nodes.
  3. Missing tags trigger explicit governance warning.

3.4 Example Output

$ ansible-inventory -i inventory_cloud.yml --graph
@all:
  |--@tag_env_prod
  |--@tag_role_web

3.7 Real World Outcome

  • New tagged host appears automatically in group output.
  • Targeted ping works without editing inventory files.

4. Solution Architecture

provider credentials -> plugin config -> filtered hosts -> keyed groups -> run scope

5. Implementation Guide

5.3 The Core Question You’re Answering

“How do I preserve targeting accuracy when the fleet changes faster than humans can edit files?”

5.4 Concepts You Must Understand First

  1. Plugin configuration model.
  2. Cloud tag taxonomy and ownership.
  3. Safe fallback when provider calls fail.

5.5 Questions to Guide Your Design

  1. Which tags are mandatory for targetability?
  2. What should happen when discovery returns zero hosts unexpectedly?

5.6 Thinking Exercise

Design a tag policy for env, role, and criticality and map to group names.

5.7 Interview Questions

  1. Why are plugin inventories preferred over scripts?
  2. How do you prevent accidental broad targeting?
  3. What are safe fallback strategies during provider outages?

5.8 Hints in Layers

  • Hint 1: Validate graph output first.
  • Hint 2: Start with narrow filters.
  • Hint 3: Add cache only after correctness.
  • Hint 4: Store expected group snapshot for comparison.

6. Testing Strategy

  1. Baseline discovery with expected tags.
  2. Add one host and verify automatic inclusion.
  3. Remove tag and confirm host exclusion from target group.

7. Common Pitfalls & Debugging

Pitfall Symptom Solution
loose filters wrong hosts targeted tighten plugin filters
tag inconsistency missing hosts enforce tag policy
stale cache outdated group map adjust/disable cache in critical runs

8. Extensions & Challenges

  • Multi-region grouping and failover groups.
  • Drift alerts when critical tags are missing.
  • Inventory graph diff in CI.

9. Real-World Connections

Dynamic inventory is standard in autoscaling infrastructure where static inventories cannot keep pace.


10. Resources

  • Dynamic inventory docs
  • Cloud provider inventory plugin docs
  • Precedence rules docs

11. Self-Assessment Checklist

  • I can explain and prove group generation logic.
  • I can prevent broad targeting via filters.
  • I can handle discovery failures with a documented fallback.

12. Submission / Completion Criteria

  • Minimum: working dynamic group and targeted ping.
  • Full: includes tag governance and failure-path handling.
  • Excellence: automated inventory diff guardrail.