Add disconnect to the Transport trait to allow groups to be properly run
Since I refactored a Transport to allow for maintaining a connection, subsequent commands were being run on the same target. This ensures that when a group is being run, that the session is flushed between connections
This commit is contained in:
parent
3ae98839c7
commit
6e0c76dd70
|
@ -608,7 +608,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zap-cli"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"colored",
|
||||
"gumdrop",
|
||||
|
@ -624,7 +624,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zap-model"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"handlebars",
|
||||
"log",
|
||||
|
|
13
README.adoc
13
README.adoc
|
@ -56,6 +56,19 @@ Once this has been set up, you can run:
|
|||
zap plan hello.zplan -t alpha --dry-run
|
||||
----
|
||||
|
||||
== Command Line
|
||||
|
||||
The `zap` command line interface has a number of subcommands that can help with
|
||||
the development and deployment of tasks and plans.
|
||||
|
||||
=== cmd
|
||||
|
||||
=== check
|
||||
|
||||
=== plan
|
||||
|
||||
=== task
|
||||
|
||||
|
||||
== Examples
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "zap-cli"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["R. Tyler Croy <rtyler@brokenco.de>"]
|
||||
edition = "2018"
|
||||
description = "A simple configuration management and orchestration tool"
|
||||
|
|
|
@ -10,6 +10,7 @@ pub mod ssh;
|
|||
*/
|
||||
pub trait Transport {
|
||||
fn connect(&mut self, target: &Target) -> bool;
|
||||
fn disconnect(&mut self);
|
||||
fn run_group(
|
||||
&mut self,
|
||||
cmd: &ExecutableTask,
|
||||
|
|
|
@ -40,18 +40,31 @@ impl Transport for Ssh {
|
|||
// XXX: This is inefficient
|
||||
for target in inventory.targets.iter() {
|
||||
if &target.name == target_name {
|
||||
println!("Running on `{}`", target.name);
|
||||
println!("Running on `{}` {}", target.name, target.uri);
|
||||
status = self.run(command, &target, dry_run);
|
||||
self.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
status
|
||||
}
|
||||
|
||||
fn disconnect(&mut self) {
|
||||
debug!("Disconnecting");
|
||||
if self.connected {
|
||||
self.session.disconnect(None, "Zappidy doo-da", None);
|
||||
// There doesn't seem to be any cleaner way to close other than
|
||||
//.just dropping the session
|
||||
self.session = Session::new().unwrap();
|
||||
}
|
||||
self.connected = false;
|
||||
}
|
||||
|
||||
fn connect(&mut self, target: &Target) -> bool {
|
||||
if self.connected {
|
||||
return self.connected;
|
||||
}
|
||||
debug!("Connecting to {}", target.uri);
|
||||
let tcp = TcpStream::connect(format!("{}:22", target.uri)).unwrap();
|
||||
self.session.set_tcp_stream(tcp);
|
||||
self.session.handshake().unwrap();
|
||||
|
|
|
@ -8,7 +8,7 @@ targets:
|
|||
- name: freebsd-tor
|
||||
uri: 192.168.1.41
|
||||
- name: gopher
|
||||
uri: 192.168.1.41
|
||||
uri: 192.168.1.42
|
||||
- name: zap-freebsd
|
||||
uri: 192.168.1.224
|
||||
config:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "zap-model"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["R. Tyler Croy <rtyler@brokenco.de>"]
|
||||
edition = "2018"
|
||||
description = "Internal models for zap, a simple configuration management tool"
|
||||
|
|
Loading…
Reference in New Issue