Module: SSHKit::Custom::DSL::ConfigStatements

Included in:
SSHKit::Custom::DSL
Defined in:
lib/sshkit/custom/dsl/config_statements.rb

Instance Method Summary collapse

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

Parameters:

  • who (String, Hash<String, String>)

    User and group to be set.

Yields:

  • Host for further DSL execution

DSL:



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.

Parameters:

  • opts (Hash<Symbol, String>)

    Default options for the runner

DSL:



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| ... }

Parameters:

  • hosts (Array<String>)

    the DNS of the hosts to execute the following blocks

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :in (Symbol)

    Chooses the runner to be used

    • :parallel => Parallel
    • :sequence => Sequential
    • :groups => Group
  • :wait (Integer)

    Amount of seconds to sleep between executions for Sequential and Parallel Runner

  • :limit (Integer)

    Amount of hosts to use in one Batch for Group Runner

Yields:

  • Host for further DSL execution

See Also:

  • Config::Store#create_runner

DSL:



20
21
22
23
24
25
26
# File 'lib/sshkit/custom/dsl/config_statements.rb', line 20

def on(hosts, options = {}, &block)
  hosts = Array(hosts).map { |rh| Host(rh) }.uniq

  _setup_runner(hosts, options)

  _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.

Parameters:

  • environment (Hash<String, String>)

    Environment variables to be set

Yields:

  • Host for further DSL execution

DSL:



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.

Parameters:

  • directory (String)

    The directory within the statements are executed

Yields:

  • Host for further DSL execution

DSL:



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