PromptHub
DevOps Infrastructure Automation

Stop Writing Ansible Playbooks! mgmt Is the Real-Time Config Tool You Need

B

Bright Coding

Author

13 min read
18 views
Stop Writing Ansible Playbooks! mgmt Is the Real-Time Config Tool You Need

Stop Writing Ansible Playbooks! mgmt Is the Real-Time Config Tool You Need

What if your infrastructure could react to changes instantly—not in 30 minutes, not after the next cron job, but in the very moment something happens? If you've ever stared at a loading screen while Ansible crawls through 500 hosts, or watched Puppet slowly converge while your production system burned, you know the agony of polling-based configuration management. The dirty secret of our industry? Most tools are stuck in 2008, pretending that batch-processing your infrastructure is still acceptable.

But what if I told you there's a tool that flips this paradigm entirely? A tool that doesn't just check your systems periodically, but lives inside them—breathing, watching, reacting in real-time? Enter mgmt, the next-generation distributed, event-driven, parallel configuration management system that's making senior SREs quietly abandon their old tooling. Built by James Shubin (purpleidea) and battle-tested for over a decade, mgmt isn't an incremental improvement—it's a complete reimagining of how infrastructure automation should work.

In this deep dive, I'll expose why mgmt is the secret weapon top platform engineers are adopting, how its reactive mcl language eliminates entire classes of bugs, and why its decentralized cluster architecture makes Kubernetes-style distributed scheduling feel primitive by comparison. By the end, you'll understand why "event-driven" isn't just a buzzword—it's the future of infrastructure, and mgmt is already living there.


What Is mgmt? The Config Management Tool That Broke the Rules

mgmt (pronounced "management") is a real-time automation engine and domain-specific language that redefines configuration management through reactive, event-driven programming. Created by James Shubin and open-sourced on GitHub, this Go-based project has been meticulously refined for over ten years, building a production-hardened foundation that most newer tools can only dream of achieving.

Unlike traditional tools that operate on a pull or push model with periodic convergence, mgmt establishes continuous, closed-loop feedback systems. It doesn't just enforce state—it maintains it, perpetually, reacting to any deviation or external change as it occurs. The system runs as a decentralized cluster of agents, each exchanging information in real-time, creating a living, self-healing infrastructure fabric.

The project's architecture centers on two core components: the engine (written in Go) and mcl (mgmt configuration language), a functional, reactive DSL designed specifically for infrastructure scenarios. This isn't YAML with extra steps—mcl is a full programming language with first-class functions, reactive streams, and built-in primitives for distributed coordination.

Why is mgmt trending now? The infrastructure landscape has finally caught up to its vision. As organizations adopt dynamic cloud-native architectures, service meshes, and edge computing, the limitations of static, polling-based tools have become unbearable. mgmt's real-time reactive model aligns perfectly with modern observability-driven operations, where systems must respond to metrics, schedules, and events without human intervention or batch delays.

The project boasts impressive credentials: a clean Go Report Card, active CI/CD through GitHub Actions, comprehensive godoc documentation, and an engaged Matrix community. Enterprise backing comes from m9rx, which offers commercial support and services for organizations deploying mgmt at scale.


Key Features: Why mgmt Leaves Ansible and Puppet in the Dust

mgmt isn't just different—it's architecturally superior for modern infrastructure challenges. Here's the technical breakdown of what makes it extraordinary:

Real-Time Reactive Execution

Traditional tools poll. mgmt reacts. When a file changes, a metric threshold crosses, or a schedule triggers, mgmt responds immediately. This is achieved through a persistent, event-driven engine that maintains continuous evaluation graphs, not discrete task lists.

Decentralized Cluster Architecture

Run mgmt as a distributed cluster without centralized bottlenecks. Agents communicate peer-to-peer, sharing state and coordinating resources through built-in consensus mechanisms. This eliminates single points of failure and scales horizontally without architectural changes.

mcl: A Language Built for Infrastructure

mcl is functional and reactive, not imperative. Variables automatically re-evaluate when their dependencies change. No more notify handlers or complex ordering directives—the language's semantics guarantee correct propagation of changes.

Closed-Loop Feedback Systems

mgmt can integrate with monitoring and metrics to create self-regulating infrastructure. Imagine auto-scaling that doesn't just react to CPU thresholds but continuously optimizes based on real-time business metrics, cost constraints, and SLA requirements—all expressed in declarative mcl code.

Flexible Execution Modes

Run continuously for always-on enforcement, intermittently for resource-constrained environments, or on-demand for CI/CD pipelines. The same code works across all modes without modification.

Extensible Resource Model

Resources and functions aren't hardcoded. The plugin architecture allows custom resources in Go, and new functions integrate seamlessly into the mcl type system.

Built-In Scheduling and Coordination

Distributed resource scheduling across clusters is a first-class primitive, not an afterthought. Specify constraints like "run on maximum two hosts" and let mgmt handle election, failover, and rebalancing automatically.


Use Cases: Where mgmt Absolutely Dominates

1. Dynamic Security Posture Management

Security policies that change based on time, threat level, or compliance requirements are trivial with mgmt. The friday-readonly example (shown below) demonstrates time-based policy enforcement that updates instantly at midnight—no cron jobs, no delayed convergence windows.

2. Intelligent Edge Computing Orchestration

Deploy mgmt agents across thousands of edge devices. The decentralized cluster automatically handles partition tolerance, allowing subsets of infrastructure to operate autonomously during network disruptions, then seamlessly reconcile when connectivity restores.

3. Cost-Optimized Cloud Auto-Scaling

Combine real-time pricing APIs with workload metrics in mcl. Your infrastructure can shift between spot instances, reserved capacity, and on-demand resources based on actual cost curves, not static thresholds—with decisions propagated across the cluster in milliseconds.

4. High-Frequency Trading Infrastructure

For financial services where microsecond latency matters, mgmt's event-driven model eliminates the polling overhead that traditional tools introduce. Configuration changes propagate through the trading stack without the jitter of periodic convergence runs.

5. Multi-Tenant SaaS Platform Isolation

Use mgmt's scheduling primitives to ensure tenant workloads distribute across infrastructure with hard isolation guarantees. The cluster-aware scheduling prevents resource concentration that could violate compliance or create noisy-neighbor scenarios.


Step-by-Step Installation & Setup Guide

Getting mgmt running is straightforward for any Go-savvy operator. Here's the complete path from zero to reactive infrastructure:

Prerequisites

  • Go 1.18+ (for building from source)
  • Git
  • A Linux or macOS system (primary targets; BSD and Windows experimental)

Installation from Source

# Clone the repository
git clone https://github.com/purpleidea/mgmt.git
cd mgmt

# Build the project
make build

# Or install directly to $GOPATH/bin
make install

# Verify installation
mgmt --version

Binary Installation (Future Releases)

While mgmt currently emphasizes source builds for bleeding-edge features, check the releases page for precompiled binaries as the project approaches broader distribution packaging.

Your First mcl File

Create hello.mcl:

# A minimal mgmt configuration
print "hello world" {}

Run it:

mgmt run --tmp-prefix lang hello.mcl

The --tmp-prefix flag uses a temporary directory for state, perfect for experimentation without persistent side effects.

Continuous Mode Setup

For production-style continuous enforcement:

# Run with persistent state directory
mgmt run --prefix /var/lib/mgmt lang your-config.mcl

Cluster Configuration

Deploy across multiple nodes by specifying seeds:

# On the first node
mgmt run --hostname node1.example.com lang cluster.mcl

# On subsequent nodes
mgmt run --hostname node2.example.com --seeds http://node1.example.com:2379 lang cluster.mcl

The embedded etcd cluster handles service discovery and state coordination automatically.


REAL Code Examples from the Repository

The mgmt README contains powerful, production-ready examples that demonstrate mcl's unique capabilities. Let's dissect them with detailed technical commentary.

Example 1: Time-Based Dynamic File Permissions

This is the canonical mgmt demonstration—security policy that reacts to calendar events in real-time:

import "datetime"                          # Import the datetime module for time functions

# Evaluate whether today is Friday by comparing weekday name
$is_friday = datetime.weekday(datetime.now()) == "friday"

file "/srv/files/" {                        # Declare a file resource at this path
	state => $const.res.file.state.exists,   # Ensure the directory exists (constant reference)
	mode => if $is_friday {                  # REACTIVE CONDITION: this re-evaluates instantly!
		"0550"                               # Read-only for group on Fridays (security mode)
	} else {
		"0770"                               # Full read-write otherwise (operational mode)
	},
}

What's happening technically? The datetime.now() function returns a reactive stream that updates when the system time changes. When midnight strikes Friday, $is_friday transitions to true, and the mode property immediately reconciles to "0550". No cron job. No 30-minute Puppet run interval. The engine's graph evaluation detects the changed dependency and propagates the update through the resource graph.

Compare this to Ansible: you'd need cron integration, a playbook that checks ansible_date_time.weekday, and either frequent execution or exact timing coordination. With mgmt, the semantics of time are native to the language.

Example 2: Distributed Cluster Scheduling

This example showcases mgmt's distributed systems prowess—dynamic resource election across a cluster:

import "sys"                              # System information functions (hostname, etc.)
import "world"                             # Cluster-wide coordination primitives

# Define scheduling policy for a distributed workload
schedule "mygroup42" {                     # Named scheduling group
	strategy => "rr",                       # Round-robin distribution strategy
	max => 2,                               # HARD CONSTRAINT: maximum 2 concurrent hosts
	ttl => 10,                              # Time-to-live for scheduling decisions (seconds)
}

# Subscribe to the reactive scheduling result stream
$set = world.schedule("mygroup42")         # Returns a SET that updates as cluster changes

if sys.hostname() in $set {                # CONDITIONAL: only execute on elected hosts
	# This block executes ONLY on the 2 chosen machines
	print "i got scheduled" {}              # Replace with actual workload (service, container, etc.)
}

The distributed systems magic: world.schedule() returns a reactive set backed by cluster consensus. As nodes join or leave, the set automatically rebalances. If a scheduled node fails, the TTL expires, and the cluster elects a replacement within seconds. The if condition is reactive—when $set changes, nodes seamlessly start or stop their workload without explicit orchestration commands.

This is service mesh-level coordination without sidecars, without Kubernetes complexity, expressed in 10 lines of infrastructure code. The strategy => "rr" enables round-robin, but mgmt supports other strategies, and custom schedulers are implementable through the plugin system.

Example 3: Implicit Reactive Dependencies

While not explicitly shown in separate code, the README emphasizes a critical pattern: dependencies in mcl are automatic and reactive. Consider this conceptual expansion:

import "net"
import "exec"

# Reactive: updates when IP changes (DHCP renewals, VM migrations, etc.)
$my_ip = net.lookup_ip("database.internal")

exec "update-config" {
	cmd => "/usr/local/bin/update-db-config",  # Runs automatically when $my_ip changes
	args => ["--host", $my_ip],                # Arguments are reactive dependencies
}

Here, exec implicitly depends on net.lookup_ip(). When the DNS record updates, the command re-executes immediately. In traditional tools, you'd need explicit notify chains, handler definitions, and careful ordering. mcl eliminates this boilerplate through functional reactive programming semantics.


Advanced Usage & Best Practices

Design for Reactivity, Not Procedural Logic

The biggest mental shift: stop thinking in steps. mcl rewards declarative, graph-oriented thinking. Express what should be true, not how to achieve it. The engine optimizes execution order automatically.

Leverage Persistent Mode for Critical Infrastructure

Use continuous execution (mgmt run without --tmp-prefix) for production systems. The persistent state enables crash recovery and ensures no gap between desired and actual state.

Cluster Sizing and Network Partitions

For cluster deployments, maintain odd numbers of nodes for consensus stability. The embedded etcd tolerates (n-1)/2 failures. Design workloads to be partition-tolerant where possible—mgmt handles reconciliation post-partition, but your applications should degrade gracefully.

Resource Graph Debugging

Use mgmt graph --lang your-config.mcl to visualize the dependency graph before deployment. This reveals implicit dependencies and potential cycles.

Custom Resource Development

When built-in resources insufficient, implement custom resources in Go. The resource guide provides the interface contracts. Start by studying existing resources in the engine/resources/ directory.

Integration with Existing Tooling

mgmt doesn't require wholesale replacement. Use it for dynamic, real-time components while keeping stable, slow-changing configurations in existing tools. The Puppet guide demonstrates hybrid patterns.


Comparison with Alternatives: Why mgmt Wins

Dimension mgmt Ansible Puppet Chef SaltStack
Execution Model Event-driven, continuous Push, ad-hoc Pull, periodic Pull, periodic Push/pull hybrid
Reaction Latency Milliseconds Minutes to hours 30 min default 30 min default Minutes
Distributed Coordination Native, peer-to-peer None (requires external) Limited (PuppetDB) Limited Some (Salt Mine)
Language Paradigm Functional reactive Procedural (YAML/Jinja) Declarative (DSL) Imperative (Ruby) Declarative (YAML/Jinja)
Cluster Scheduling Built-in primitives None None None Limited
Closed-Loop Feedback Native Manual (external scripts) Manual Manual Manual
Learning Curve Moderate (new paradigm) Low Moderate High Moderate
Production Maturity 10+ years, growing adoption Very mature Very mature Mature Mature

The verdict: Choose mgmt when you need real-time responsiveness, distributed coordination without orchestrator complexity, or reactive infrastructure that self-heals from events. Stick with traditional tools for simple, static configurations where latency is irrelevant and team familiarity dominates.


FAQ: Your Burning mgmt Questions Answered

Is mgmt production-ready?

Absolutely. With over ten years of development and active production deployments across corporate and individual users, mgmt has a solid, polished architecture. Enterprise support is available through m9rx.

How does mgmt handle secrets?

mgmt integrates with standard secret management through its extensible resource model. Use environment variables, file-based secrets, or implement custom resources for Vault, AWS Secrets Manager, or similar services.

Can I migrate from Ansible/Puppet gradually?

Yes. The Puppet guide demonstrates hybrid approaches. Start with event-critical components in mgmt, maintain stable configurations in existing tools.

What platforms does mgmt support?

Primary targets are Linux and macOS. BSD and Windows support is experimental. The Go-based engine compiles wherever Go runs, but resource implementations may have platform-specific dependencies.

How does the mcl learning curve compare to YAML?

mcl is more expressive than YAML, requiring understanding of functional reactive concepts. However, for equivalent functionality, mcl often requires dramatically less code. The introductory guide accelerates onboarding.

Is there a managed/cloud version?

Currently mgmt is self-hosted. The decentralized architecture intentionally avoids centralized control planes. m9rx offers enterprise consulting and support for large-scale deployments.

How do I debug reactive code that executes unpredictably?

Use mgmt graph to visualize evaluation order. Set DEBUG=true in main.go for verbose logging. The functional nature means no hidden mutable state—trace dependency chains through explicit variable references.


Conclusion: The Future of Infrastructure Is Reactive—Join It Now

Configuration management has been stuck in a polling paradigm for too long. We've accepted 30-minute convergence windows as normal. We've built elaborate orchestration layers to compensate for fundamentally batch-oriented tools. It doesn't have to be this way.

mgmt proves that real-time, reactive infrastructure automation isn't just possible—it's practical, production-ready, and surprisingly elegant. The mcl language's functional reactive semantics eliminate entire categories of timing bugs and ordering failures. The decentralized cluster architecture provides distributed coordination that rivals dedicated orchestrators with a fraction of the complexity. And the ten-year development history means you're not adopting bleeding-edge vaporware—you're joining a mature, growing ecosystem.

The infrastructure engineers quietly replacing their Ansible playbooks with mcl files aren't chasing novelty. They're escaping the latency trap that polling-based tools impose. They're building systems that respond to the world as it actually operates: continuously, unpredictably, in real-time.

Your move. Clone the repository, run your first mcl file, and experience what configuration management should have been all along. The future is reactive, and mgmt is already there—waiting for you to catch up.

⭐ Star mgmt on GitHub | 📖 Read the Docs | 💬 Join the Matrix Community


Happy hacking!

Comments (0)

Comments are moderated before appearing.

No comments yet. Be the first to share your thoughts!

Support us! ☕