Skip to content

Commit 8867704

Browse files
cavcrosbytaru-garg-hashicorp
authored andcommitted
Replace deprecated Ansible inventory file option
This was done because the --inventory-file option for Ansible is anticipated to be removed as of the ansible-core package version '2.23'.
1 parent f2960d5 commit 8867704

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

plugins/provisioners/ansible/provisioner/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def prepare_common_command_arguments
164164
@command_arguments << "--limit=#{@machine.name}"
165165
end
166166

167-
@command_arguments << "--inventory-file=#{inventory_path}"
167+
@command_arguments << "--inventory=#{inventory_path}"
168168
@command_arguments << "--extra-vars=#{extra_vars_argument}" if config.extra_vars
169169
@command_arguments << "--#{@lexicon[:become]}" if config.become
170170
@command_arguments << "--#{@lexicon[:become_user]}=#{config.become_user}" if config.become_user

test/unit/plugins/provisioners/ansible/provisioner_test.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def self.it_should_set_arguments_and_environment_variables(
9696
expect(args[1]).to eq("--connection=ssh")
9797
expect(args[2]).to eq("--timeout=30")
9898

99-
inventory_count = args.count { |x| x.match(/^--inventory-file=.+$/) if x.is_a?(String) }
99+
inventory_count = args.count { |x| x.match(/^--inventory=.+$/) if x.is_a?(String) }
100100
expect(inventory_count).to be > 0
101101

102102
expect(args[args.length-2]).to eq("playbook.yml")
@@ -200,9 +200,9 @@ def self.it_should_create_and_use_generated_inventory(with_user = true)
200200

201201
it "sets as ansible inventory the directory containing the auto-generated inventory file" do
202202
expect(Vagrant::Util::Subprocess).to receive(:execute).with('ansible-playbook', any_args) { |*args|
203-
inventory_index = args.rindex("--inventory-file=#{generated_inventory_dir}")
203+
inventory_index = args.rindex("--inventory=#{generated_inventory_dir}")
204204
expect(inventory_index).to be > 0
205-
expect(find_last_argument_after(inventory_index, args, /--inventory-file=\w+/)).to be(false)
205+
expect(find_last_argument_after(inventory_index, args, /--inventory=\w+/)).to be(false)
206206
}.and_return(default_execute_result)
207207
end
208208
end
@@ -621,7 +621,7 @@ def ensure_that_config_is_valid
621621
"-l localhost",
622622
"--limit=foo",
623623
"--limit=bar",
624-
"--inventory-file=/forget/it/my/friend",
624+
"--inventory=/forget/it/my/friend",
625625
"--user=lion",
626626
"--new-arg=yeah"]
627627
end
@@ -639,7 +639,7 @@ def ensure_that_config_is_valid
639639
it "sets raw arguments after arguments related to supported options" do
640640
expect(Vagrant::Util::Subprocess).to receive(:execute).with('ansible-playbook', any_args) { |*args|
641641
expect(args.index("--user=lion")).to be > args.index("--user=testuser")
642-
expect(args.index("--inventory-file=/forget/it/my/friend")).to be > args.index("--inventory-file=#{generated_inventory_dir}")
642+
expect(args.index("--inventory=/forget/it/my/friend")).to be > args.index("--inventory=#{generated_inventory_dir}")
643643
expect(args.index("--limit=bar")).to be > args.index("--limit=all")
644644
expect(args.index("--skip-tags=ignored")).to be > args.index("--skip-tags=foo,bar")
645645
}.and_return(default_execute_result)
@@ -736,8 +736,8 @@ def ensure_that_config_is_valid
736736

737737
it "does not generate the inventory and uses given inventory path instead" do
738738
expect(Vagrant::Util::Subprocess).to receive(:execute).with('ansible-playbook', any_args) { |*args|
739-
expect(args).to include("--inventory-file=#{existing_file}")
740-
expect(args).not_to include("--inventory-file=#{generated_inventory_file}")
739+
expect(args).to include("--inventory=#{existing_file}")
740+
expect(args).not_to include("--inventory=#{generated_inventory_file}")
741741
expect(File.exist?(generated_inventory_file)).to be(false)
742742
}.and_return(default_execute_result)
743743
end
@@ -912,7 +912,7 @@ def ensure_that_config_is_valid
912912

913913
it "shows the ansible-playbook command and set verbosity to '-#{verbose_option}' level" do
914914
expect(machine.env.ui).to receive(:detail)
915-
.with("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 --connection=ssh --timeout=30 --limit=\"machine1\" --inventory-file=#{generated_inventory_dir} -#{verbose_option} playbook.yml")
915+
.with("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 --connection=ssh --timeout=30 --limit=\"machine1\" --inventory=#{generated_inventory_dir} -#{verbose_option} playbook.yml")
916916
end
917917
end
918918

@@ -926,7 +926,7 @@ def ensure_that_config_is_valid
926926

927927
it "shows the ansible-playbook command and set verbosity to '-#{verbose_option}' level" do
928928
expect(machine.env.ui).to receive(:detail)
929-
.with("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 --connection=ssh --timeout=30 --limit=\"machine1\" --inventory-file=#{generated_inventory_dir} -#{verbose_option} playbook.yml")
929+
.with("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 --connection=ssh --timeout=30 --limit=\"machine1\" --inventory=#{generated_inventory_dir} -#{verbose_option} playbook.yml")
930930
end
931931
end
932932
end
@@ -941,7 +941,7 @@ def ensure_that_config_is_valid
941941

942942
it "shows the ansible-playbook command and set verbosity to '-v' level" do
943943
expect(machine.env.ui).to receive(:detail)
944-
.with("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 --connection=ssh --timeout=30 --limit=\"machine1\" --inventory-file=#{generated_inventory_dir} -v playbook.yml")
944+
.with("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 --connection=ssh --timeout=30 --limit=\"machine1\" --inventory=#{generated_inventory_dir} -v playbook.yml")
945945
end
946946
end
947947

@@ -1172,7 +1172,7 @@ def ensure_that_config_is_valid
11721172

11731173
it "shows the ansible-playbook command, with additional quotes when required" do
11741174
expect(machine.env.ui).to receive(:detail)
1175-
.with(%Q(PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_ROLES_PATH='/up/to the stars' ANSIBLE_CONFIG='#{existing_file}' ANSIBLE_HOST_KEY_CHECKING=true ANSIBLE_SSH_ARGS='-o IdentitiesOnly=yes -o IdentityFile=/my/key1 -o IdentityFile=/my/key2 -o ForwardAgent=yes -o ControlMaster=no -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --ask-sudo-pass --ask-vault-pass --limit="machine*:&vagrant:!that_one" --inventory-file=#{generated_inventory_dir} --extra-vars=\\{\\"var1\\":\\"string\\ with\\ \\'apo\\$trophe\\$\\',\\ \\\\\\\\,\\ \\\\\\"\\ and\\ \\=\\",\\"var2\\":\\{\\"x\\":42\\}\\} --sudo --sudo-user=deployer -vvv --vault-password-file=#{existing_file} --tags=db,www --skip-tags=foo,bar --start-at-task="joe's awesome task" --why-not --su-user=foot --ask-su-pass --limit=all --private-key=./myself.key --extra-vars='{\"var3\":\"foo\"}' playbook.yml))
1175+
.with(%Q(PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_ROLES_PATH='/up/to the stars' ANSIBLE_CONFIG='#{existing_file}' ANSIBLE_HOST_KEY_CHECKING=true ANSIBLE_SSH_ARGS='-o IdentitiesOnly=yes -o IdentityFile=/my/key1 -o IdentityFile=/my/key2 -o ForwardAgent=yes -o ControlMaster=no -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --ask-sudo-pass --ask-vault-pass --limit="machine*:&vagrant:!that_one" --inventory=#{generated_inventory_dir} --extra-vars=\\{\\"var1\\":\\"string\\ with\\ \\'apo\\$trophe\\$\\',\\ \\\\\\\\,\\ \\\\\\"\\ and\\ \\=\\",\\"var2\\":\\{\\"x\\":42\\}\\} --sudo --sudo-user=deployer -vvv --vault-password-file=#{existing_file} --tags=db,www --skip-tags=foo,bar --start-at-task="joe's awesome task" --why-not --su-user=foot --ask-su-pass --limit=all --private-key=./myself.key --extra-vars='{\"var3\":\"foo\"}' playbook.yml))
11761176
end
11771177
end
11781178

0 commit comments

Comments
 (0)