Skip to content

Commit

Permalink
provisioners/ansible: increase connection timeout
Browse files Browse the repository at this point in the history
This change helps to avoid troubles like reported in #5018 and #4860.

Note that for sake of configuration simplicity, no new `ansible.timeout`
option has been added. The users who want to set a different value can
rely on `ansible.raw_arguments`.
  • Loading branch information
gildegoma committed Jan 12, 2015
1 parent fafaa00 commit 2ecad8b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ BUG FIXES:
- guests/funtoo: fix incorrect path in configure networks [GH-4812]
- plugins/login: allow users to login with a token [GH-5145]
- provisioners/ansible: fix SSH settings to support more than 5 ssh keys [GH-5017]
- provisioners/ansible: increase ansible connection timeout to 30 seconds [GH-5175]

## 1.7.2 (January 6, 2015)

Expand Down
6 changes: 6 additions & 0 deletions plugins/provisioners/ansible/provisioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def provision
# but can be enabled via raw_arguments option.
options << "--connection=ssh"

# Increase the SSH connection timeout, as the Ansible default value (10 seconds)
# is a bit demanding for some overloaded developer boxes. This is particularly
# helpful when additioal virtual networks are configured, as their availability
# is not controlled during vagrant boot process.
options << "--timeout=30"

# By default we limit by the current machine, but
# this can be overridden by the `limit` option.
if config.limit
Expand Down
29 changes: 15 additions & 14 deletions test/unit/plugins/provisioners/ansible/provisioner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def find_last_argument_after(ref_index, ansible_playbook_args, arg_pattern)
#

def self.it_should_set_arguments_and_environment_variables(
expected_args_count = 6, expected_vars_count = 4, expected_host_key_checking = false, expected_transport_mode = "ssh")
expected_args_count = 7, expected_vars_count = 4, expected_host_key_checking = false, expected_transport_mode = "ssh")

it "sets implicit arguments in a specific order" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
Expand All @@ -73,6 +73,7 @@ def self.it_should_set_arguments_and_environment_variables(
expect(args[1]).to eq("--private-key=#{machine.ssh_info[:private_key_path][0]}")
expect(args[2]).to eq("--user=#{machine.ssh_info[:username]}")
expect(args[3]).to eq("--connection=ssh")
expect(args[4]).to eq("--timeout=30")

inventory_count = args.count { |x| x =~ /^--inventory-file=.+$/ }
expect(inventory_count).to be > 0
Expand Down Expand Up @@ -272,7 +273,7 @@ def self.it_should_create_and_use_generated_inventory
config.host_key_checking = true
end

it_should_set_arguments_and_environment_variables 6, 4, true
it_should_set_arguments_and_environment_variables 7, 4, true
end

describe "with boolean (flag) options disabled" do
Expand All @@ -284,7 +285,7 @@ def self.it_should_create_and_use_generated_inventory
config.sudo_user = 'root'
end

it_should_set_arguments_and_environment_variables 7
it_should_set_arguments_and_environment_variables 8
it_should_set_optional_arguments({ "sudo_user" => "--sudo-user=root" })

it "it does not set boolean flag when corresponding option is set to false" do
Expand Down Expand Up @@ -313,7 +314,7 @@ def self.it_should_create_and_use_generated_inventory
"--new-arg=yeah"]
end

it_should_set_arguments_and_environment_variables 17, 4, false, "paramiko"
it_should_set_arguments_and_environment_variables 18, 4, false, "paramiko"

it "sets all raw arguments" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
Expand Down Expand Up @@ -369,7 +370,7 @@ def self.it_should_create_and_use_generated_inventory
config.ask_vault_pass = true
end

it_should_set_arguments_and_environment_variables 7
it_should_set_arguments_and_environment_variables 8

it "should ask the vault password" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
Expand All @@ -383,7 +384,7 @@ def self.it_should_create_and_use_generated_inventory
config.vault_password_file = existing_file
end

it_should_set_arguments_and_environment_variables 7
it_should_set_arguments_and_environment_variables 8

it "uses the given vault password file" do
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
Expand All @@ -397,7 +398,7 @@ def self.it_should_create_and_use_generated_inventory
config.raw_ssh_args = ['-o ControlMaster=no', '-o ForwardAgent=no']
end

it_should_set_arguments_and_environment_variables 6, 4
it_should_set_arguments_and_environment_variables 7, 4
it_should_explicitly_enable_ansible_ssh_control_persist_defaults

it "passes custom SSH options via ANSIBLE_SSH_ARGS with the highest priority" do
Expand Down Expand Up @@ -431,7 +432,7 @@ def self.it_should_create_and_use_generated_inventory
ssh_info[:private_key_path] = ['/path/to/my/key', '/an/other/identity', '/yet/an/other/key']
end

it_should_set_arguments_and_environment_variables 6, 4
it_should_set_arguments_and_environment_variables 7, 4
it_should_explicitly_enable_ansible_ssh_control_persist_defaults

it "passes additional Identity Files via ANSIBLE_SSH_ARGS" do
Expand All @@ -448,7 +449,7 @@ def self.it_should_create_and_use_generated_inventory
ssh_info[:forward_agent] = true
end

it_should_set_arguments_and_environment_variables 6, 4
it_should_set_arguments_and_environment_variables 7, 4
it_should_explicitly_enable_ansible_ssh_control_persist_defaults

it "enables SSH-Forwarding via ANSIBLE_SSH_ARGS" do
Expand All @@ -467,7 +468,7 @@ def self.it_should_create_and_use_generated_inventory

it "shows the ansible-playbook command" do
expect(machine.env.ui).to receive(:detail).with { |full_command|
expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --private-key=/path/to/my/key --user=testuser --connection=ssh --limit='machine1' --inventory-file=#{generated_inventory_dir} playbook.yml")
expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --private-key=/path/to/my/key --user=testuser --connection=ssh --timeout=30 --limit='machine1' --inventory-file=#{generated_inventory_dir} playbook.yml")
}
end
end
Expand All @@ -477,12 +478,12 @@ def self.it_should_create_and_use_generated_inventory
config.verbose = 'v'
end

it_should_set_arguments_and_environment_variables 7
it_should_set_arguments_and_environment_variables 8
it_should_set_optional_arguments({ "verbose" => "-v" })

it "shows the ansible-playbook command" do
expect(machine.env.ui).to receive(:detail).with { |full_command|
expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --private-key=/path/to/my/key --user=testuser --connection=ssh --limit='machine1' --inventory-file=#{generated_inventory_dir} -v playbook.yml")
expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --private-key=/path/to/my/key --user=testuser --connection=ssh --timeout=30 --limit='machine1' --inventory-file=#{generated_inventory_dir} -v playbook.yml")
}
end
end
Expand Down Expand Up @@ -515,7 +516,7 @@ def self.it_should_create_and_use_generated_inventory
config.raw_ssh_args = ['-o ControlMaster=no']
end

it_should_set_arguments_and_environment_variables 20, 4, true
it_should_set_arguments_and_environment_variables 21, 4, true
it_should_explicitly_enable_ansible_ssh_control_persist_defaults
it_should_set_optional_arguments({ "extra_vars" => "--extra-vars=@#{File.expand_path(__FILE__)}",
"sudo" => "--sudo",
Expand All @@ -540,7 +541,7 @@ def self.it_should_create_and_use_generated_inventory

it "shows the ansible-playbook command, with additional quotes when required" do
expect(machine.env.ui).to receive(:detail).with { |full_command|
expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=true ANSIBLE_SSH_ARGS='-o IdentitiesOnly=yes -o IdentityFile=/my/key2 -o ForwardAgent=yes -o ControlMaster=no -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --private-key=/my/key1 --user=testuser --connection=ssh --limit='machine*:&vagrant:!that_one' --inventory-file=#{generated_inventory_dir} --extra-vars=@#{File.expand_path(__FILE__)} --sudo --sudo-user=deployer -vvv --ask-sudo-pass --ask-vault-pass --vault-password-file=#{File.expand_path(__FILE__)} --tags=db,www --skip-tags=foo,bar --start-at-task='an awesome task' --why-not --su-user=foot --ask-su-pass --limit='all' playbook.yml")
expect(full_command).to eq("PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=true ANSIBLE_SSH_ARGS='-o IdentitiesOnly=yes -o IdentityFile=/my/key2 -o ForwardAgent=yes -o ControlMaster=no -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --private-key=/my/key1 --user=testuser --connection=ssh --timeout=30 --limit='machine*:&vagrant:!that_one' --inventory-file=#{generated_inventory_dir} --extra-vars=@#{File.expand_path(__FILE__)} --sudo --sudo-user=deployer -vvv --ask-sudo-pass --ask-vault-pass --vault-password-file=#{File.expand_path(__FILE__)} --tags=db,www --skip-tags=foo,bar --start-at-task='an awesome task' --why-not --su-user=foot --ask-su-pass --limit='all' playbook.yml")
}
end
end
Expand Down

0 comments on commit 2ecad8b

Please sign in to comment.