cdk_ansible/lib.rs
1//! cdk-ansible is a development framework for defining Ansible applications, similar to AWS CDK.
2//!
3//! NOTE: The basic implementation is completely different from AWS CDK.
4//!
5//! cdk-ansible provides the following features:
6//!
7//! * Define Ansible Plays and Tasks using Rust code (wraps Ansible YAML files)
8//! * Enable parallel execution with ease (wraps the `ansible-playbook` command)
9//!
10//! ## Example
11//!
12//! ```
13//! use ::anyhow::Result;
14//! use ::cdk_ansible::{
15//! App, Stack, ExeParallel, ExePlay, ExeSequential, ExeSingle, Inventory,
16//! InventoryChild, InventoryRoot, OptU, Play, PlayOptions,
17//! };
18//!
19//! // Define a sample stack
20//! struct SampleStack {
21//! exe_play: ExePlay,
22//! }
23//!
24//! impl SampleStack {
25//! fn new(host: &str) -> Self {
26//! // Define a sample play
27//! let play = Box::new(Play {
28//! name: "sample".into(),
29//! hosts: vec![host.to_owned()].into(),
30//! options: PlayOptions::default(),
31//! tasks: vec![
32//! // Add tasks later
33//! ],
34//! });
35//!
36//! Self {
37//! exe_play: ExeSequential(vec![
38//! ExeSingle(play.clone()),
39//! ExeSequential(vec![ExeSingle(play.clone()), ExeSingle(play.clone())]),
40//! ExeParallel(vec![
41//! ExeSequential(vec![ExeSingle(play.clone()), ExeSingle(play.clone())]),
42//! ExeSingle(play.clone()),
43//! ExeParallel(vec![ExeSingle(play.clone()), ExeSingle(play.clone())]),
44//! ]),
45//! ]),
46//! }
47//! }
48//! }
49//!
50//! // Stack should implement the `Stack` trait
51//! impl Stack for SampleStack {
52//! fn name(&self) -> &str {
53//! std::any::type_name::<Self>()
54//! .split("::")
55//! .last()
56//! .expect("Failed to get a stack name")
57//! }
58//!
59//! fn exe_play(&self) -> &ExePlay {
60//! &self.exe_play
61//! }
62//! }
63//!
64//! fn run() -> Result<()> {
65//! let mut app = App::new(std::env::args().collect());
66//! let inventory = Inventory {
67//! name: "inventory".into(), // generate 'inventory.yaml' file
68//! root: InventoryRoot {
69//! all: InventoryChild {
70//! hosts: OptU::Some([("localhost".into(), None)].into_iter().collect()),
71//! ..Default::default()
72//! },
73//! },
74//! };
75//!
76//! app.add_inventory(inventory)?;
77//! app.add_stack(Box::new(SampleStack::new("localhost")))?;
78//!
79//! // app.run()? // replace `Ok(())` with `app.run()`
80//! Ok(())
81//! }
82//!
83//! fn main() {
84//! if let Err(e) = run() {
85//! eprintln!("Error: {e:?}");
86//! std::process::exit(1);
87//! }
88//! }
89//! ```
90//!
91//! ## Tutorial
92//!
93//! ### Install cdk-ansible-cli
94//!
95
96mod deploy;
97mod inventory;
98mod l2;
99pub mod prelude;
100mod types;
101mod utils;
102pub use cdk_ansible_core::core::*;
103pub use deploy::*;
104pub use inventory::*;
105pub use l2::deploy::*;
106pub use l2::types::*;
107pub use types::*;
108
109// Re-export macros
110pub use cdk_ansible_macro::*;