Module: SSHKit::Custom::DSL::Configuration
- Included in:
- SSHKit::Custom::DSL
- Defined in:
- lib/sshkit/custom/dsl/configuration.rb
Instance Method Summary collapse
- #as(who) ⇒ Object
- #config_store ⇒ Object
- #on(hosts, options = {}, &block) ⇒ Object
- #with(environment) ⇒ Object
- #within(directory) ⇒ Object
Instance Method Details
#as(who) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sshkit/custom/dsl/configuration.rb', line 42 def as(who) if who.is_a? Hash user = who[:user] || who["user"] group = who[:group] || who["group"] else user = who group = nil end execute " if ! sudo -u \#{user} whoami > /dev/null\n then echo \"You cannot switch to user '\#{user}' using sudo, please check the sudoers file\" 1>&2\n false\n fi\n EOTEST\n\n execute <<-EOTEST, verbosity: Logger::DEBUG if group\n if ! sudo -u \#{user} -g \#{group} whoami > /dev/null\n then echo \"You cannot switch to group '\#{group}' using sudo, please check the sudoers file\" 1>&2\n false\n fi\n EOTEST\n\n config_store.add_user_group user, group\n\n yield if block_given?\nensure\n config_store.pop_user_group\nend\n", verbosity: Logger::DEBUG |
#config_store ⇒ Object
6 7 8 |
# File 'lib/sshkit/custom/dsl/configuration.rb', line 6 def config_store @config_store ||= SSHKit::Custom::DSL::ConfigStore end |
#on(hosts, options = {}, &block) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/sshkit/custom/dsl/configuration.rb', line 10 def on(hosts, ={}, &block) hosts = Array(hosts).map { |rh| rh.is_a?(SSHKit::Host) ? rh : SSHKit::Host.new(rh) }.uniq config_store.backends = hosts config_store.runner_opts = config_store.runner.do_it(&block) if block_given? end |
#with(environment) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/sshkit/custom/dsl/configuration.rb', line 35 def with(environment) config_store.add_env environment yield if block_given? ensure config_store.pop_env end |
#within(directory) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sshkit/custom/dsl/configuration.rb', line 17 def within(directory) dir_to_check = File.join(config_store.backend.pwd + [directory]) execute " if test ! -d \#{dir_to_check}\n then echo \"Directory does not exist '\#{dir_to_check}'\" 1>&2\n false\n fi\n EOTEST\n\n config_store.add_pwd directory\n\n yield if block_given?\nensure\n config_store.pop_pwd\nend\n", verbosity: Logger::DEBUG |