Module: SSHKit::Custom::DSL::ConfigStatements
- Included in:
- SSHKit::Custom::DSL
- Defined in:
- lib/sshkit/custom/dsl/config_statements.rb
Instance Method Summary collapse
-
#as(who) { ... } ⇒ Object
Executes all following statements as the provided user and group (sudo).
-
#default_runner_opts(opts) ⇒ Object
Changes the default options for runner creation.
-
#on(hosts, options = {}) { ... } ⇒ Object
Starts the action to be done for named hosts.
-
#with(environment) { ... } ⇒ Object
Executes all following statements with provided environment variables.
-
#within(directory) { ... } ⇒ Object
Executes all following statements within the named directory.
Instance Method Details
#as(who) { ... } ⇒ Object
Executes all following statements as the provided user and group (sudo). After the block is executed the user and group is set back.
Possible Hash keys are :user and :group
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 66 def as(who) if who.respond_to? :fetch user = who.fetch(:user) { who.fetch('user') } group = who.fetch(:group) { who.fetch('group', nil) } else user = who group = nil end _guard_sudo_user!(user) _guard_sudo_group!(user, group) _config_store.add_user_group user, group yield if block_given? ensure _config_store.pop_user_group end |
#default_runner_opts(opts) ⇒ Object
Changes the default options for runner creation.
89 90 91 |
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 89 def default_runner_opts(opts) _config_store.default_runner_opts(opts) end |
#on(hosts, options = {}) { ... } ⇒ Object
Starts the action to be done for named hosts
For a block {|host| ... }
20 21 22 23 24 25 26 |
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 20 def on(hosts, = {}, &block) hosts = Array(hosts).map { |rh| Host(rh) }.uniq _setup_runner(hosts, ) _runner.apply_block_to_bcks(&block) if block_given? end |
#with(environment) { ... } ⇒ Object
Executes all following statements with provided environment variables. Multiple call's will the environment variables. After the block is executed the working environment variables are set back.
52 53 54 55 56 57 |
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 52 def with(environment) _config_store.add_env environment yield if block_given? ensure _config_store.pop_env end |
#within(directory) { ... } ⇒ Object
Executes all following statements within the named directory. Multiple call's will stack the directories together. After the block is executed the working directory is set back.
35 36 37 38 39 40 41 42 43 |
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 35 def within(directory) _guard_dir!(File.join(_config_store.active_backend.pwd + [directory])) _config_store.add_pwd directory yield if block_given? ensure _config_store.pop_pwd end |