volanja / ansible_spec

It's ruby gem that connect Ansible & Serverspec for Test Driven Server Configuration(or TDD).
MIT License
228 stars 57 forks source link

How can I set sudo password? #120

Closed Esfahan closed 5 years ago

Esfahan commented 5 years ago

I need to set sudo password with ansible_spec. So, I tried following command.

$ ASK_SUDO_PASSWORD=1 bundle exec rake all

But the below error appeared.

Please set sudo password to Specinfra.configuration.sudo_password.

Therefore, I cheked spec/spec_helper.rb and I found below lines.

  if ENV['ASK_BECOME_PASSWORD']
    begin
      require 'highline/import'
    rescue LoadError
      fail "highline is not available. Try installing it."
    end
    set :become_password, ask("Enter become password: ") { |q| q.echo = false }
  else
    set :become_password, ENV['BECOME_PASSWORD']
  end

There are some differences from serverspec. set become_password is defined instead of set :sudo_password in ansible_spec.

So, I fixed as follows by reference to serverspec.

-  if ENV['ASK_BECOME_PASSWORD']
+  if ENV['ASK_SUDO_PASSWORD']
    begin
      require 'highline/import'
    rescue LoadError
      fail "highline is not available. Try installing it."
    end
-    #set :become_password, ask("Enter become password: ") { |q| q.echo = false }
+    set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false }
  else
-    #set :become_password, ENV['BECOME_PASSWORD']
+    set :sudo_password, ENV['SUDO_PASSWORD']
  end

Now, I have been able to execute it with following command.

$ ASK_SUDO_PASSWORD=1 bundle exec rake all

or

$ export SUDO_PASSWORD=xxxx
$ bundle exec rake all

Why is the function implemented with different way from serverspec? Which is the better way to set sudo password?

Best regards

volanja commented 5 years ago

Yes. ansible_spec is not support ASK_SUDO_PASSWORD. Please use ASK_BECOME_PASSWORD

Because Ansible use word that become instead of sudo after Ansible 1.9.

ref #111

volanja commented 5 years ago

I found your post I think that this problem caused by mismatch between ansible_spec and serverspec. Hmmm

Esfahan commented 5 years ago

@volanja I appreciate your cooperation. https://github.com/volanja/ansible_spec/pull/125

sudo_password and ASK_SUDO_PASSWORD in spec_help.rb

I think they have nothing to do with sudo and become in ansible. They are definitions for serverspec, not ansible.