Class: GrokCLI::Docker::UpdateEtcHosts
- Inherits:
-
Object
- Object
- GrokCLI::Docker::UpdateEtcHosts
- Defined in:
- lib/grok_cli/docker/update_etc_hosts.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(config = Configuration.new) ⇒ UpdateEtcHosts
constructor
A new instance of UpdateEtcHosts.
Constructor Details
#initialize(config = Configuration.new) ⇒ UpdateEtcHosts
Returns a new instance of UpdateEtcHosts.
3 4 5 |
# File 'lib/grok_cli/docker/update_etc_hosts.rb', line 3 def initialize(config = Configuration.new) @config = config end |
Instance Method Details
#execute ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/grok_cli/docker/update_etc_hosts.rb', line 7 def execute system "\n IP=`docker-machine ip \#{@config.machine_name}`\n\n IP_MAP=\"$IP \#{@config.hostname}\"\n\n if grep -Fxq \"$IP_MAP\" /etc/hosts; then\n :\n else\n\n if sudo -n true 2>/dev/null; then\n :\n else\n echo \"You may be prompted for your password; this is to permit updating your /etc/hosts for \#{@config.hostname}\"\n fi\n\n sudo sed -i '' '/\#{@config.hostname.gsub('.', '\\.')}$/d' /etc/hosts\n\n echo $IP_MAP | sudo tee -a /etc/hosts\n fi\n\n CMD\nend\n" |