diff --git a/lib/embedded_ansible.rb b/lib/embedded_ansible.rb index 53a047e065f..1df27e1deb4 100644 --- a/lib/embedded_ansible.rb +++ b/lib/embedded_ansible.rb @@ -4,9 +4,8 @@ require "ansible_tower_client" class EmbeddedAnsible - APPLIANCE_ANSIBLE_DIRECTORY = "/opt/ansible-installer".freeze ANSIBLE_ROLE = "embedded_ansible".freeze - SETUP_SCRIPT = "#{APPLIANCE_ANSIBLE_DIRECTORY}/setup.sh".freeze + SETUP_SCRIPT = "ansible-tower-setup".freeze SECRET_KEY_FILE = "/etc/tower/SECRET_KEY".freeze CONFIGURE_EXCLUDE_TAGS = "packages,migrations,firewall,supervisor".freeze START_EXCLUDE_TAGS = "packages,migrations,firewall".freeze @@ -15,8 +14,10 @@ class EmbeddedAnsible WAIT_FOR_ANSIBLE_SLEEP = 1.second def self.available? - path = ENV["APPLIANCE_ANSIBLE_DIRECTORY"] || APPLIANCE_ANSIBLE_DIRECTORY - Dir.exist?(File.expand_path(path.to_s)) + return false unless MiqEnvironment::Command.is_appliance? + + required_rpms = Set["ansible-tower-server", "ansible-tower-setup"] + required_rpms.subset?(LinuxAdmin::Rpm.list_installed.keys.to_set) end def self.enabled? @@ -85,9 +86,10 @@ def self.api_connection def self.run_setup_script(exclude_tags) json_extra_vars = { - :minimum_var_space => 0, - :http_port => HTTP_PORT, - :https_port => HTTPS_PORT + :minimum_var_space => 0, + :http_port => HTTP_PORT, + :https_port => HTTPS_PORT, + :tower_package_name => "ansible-tower-server" }.to_json with_inventory_file do |inventory_file_path| diff --git a/spec/lib/embedded_ansible_spec.rb b/spec/lib/embedded_ansible_spec.rb index d811907403c..743d9000de3 100644 --- a/spec/lib/embedded_ansible_spec.rb +++ b/spec/lib/embedded_ansible_spec.rb @@ -2,28 +2,32 @@ require "awesome_spawn" describe EmbeddedAnsible do - before do - ENV["APPLIANCE_ANSIBLE_DIRECTORY"] = nil - end - context ".available?" do - it "returns true when installed in the default location" do - allow(Dir).to receive(:exist?).with("/opt/ansible-installer").and_return(true) + context "in an appliance" do + before do + allow(MiqEnvironment::Command).to receive(:is_appliance?).and_return(true) + end - expect(described_class.available?).to be_truthy - end + it "returns true when installed in the default location" do + installed_rpms = { + "ansible-tower-server" => "1.0.1", + "ansible-tower-setup" => "1.2.3", + "vim" => "13.5.1" + } + expect(LinuxAdmin::Rpm).to receive(:list_installed).and_return(installed_rpms) - it "returns true when installed in the custom location in env var" do - ENV["APPLIANCE_ANSIBLE_DIRECTORY"] = "/tmp" - allow(Dir).to receive(:exist?).with("/tmp").and_return(true) - allow(Dir).to receive(:exist?).with("/opt/ansible-installer").and_return(false) + expect(described_class.available?).to be_truthy + end - expect(described_class.available?).to be_truthy - end + it "returns false when not installed" do + expect(LinuxAdmin::Rpm).to receive(:list_installed).and_return("vim" => "13.5.1") - it "returns false when not installed" do - allow(Dir).to receive(:exist?).with("/opt/ansible-installer").and_return(false) + expect(described_class.available?).to be_falsey + end + end + it "returns false outside of an appliance" do + allow(MiqEnvironment::Command).to receive(:is_appliance?).and_return(false) expect(described_class.available?).to be_falsey end end @@ -88,9 +92,10 @@ let(:miq_database) { MiqDatabase.first } let(:extra_vars) do { - :minimum_var_space => 0, - :http_port => described_class::HTTP_PORT, - :https_port => described_class::HTTPS_PORT + :minimum_var_space => 0, + :http_port => described_class::HTTP_PORT, + :https_port => described_class::HTTPS_PORT, + :tower_package_name => "ansible-tower-server" }.to_json end @@ -231,7 +236,7 @@ params = options[:params] inventory_file_contents = File.read(params[:inventory=]) - expect(script_path).to eq("/opt/ansible-installer/setup.sh") + expect(script_path).to eq("ansible-tower-setup") expect(params["--"]).to be_nil expect(params[:extra_vars=]).to eq(extra_vars) expect(params[:skip_tags=]).to eq("packages,migrations,firewall,supervisor") @@ -258,7 +263,7 @@ params = options[:params] inventory_file_contents = File.read(params[:inventory=]) - expect(script_path).to eq("/opt/ansible-installer/setup.sh") + expect(script_path).to eq("ansible-tower-setup") expect(params["--"]).to be_nil expect(params[:extra_vars=]).to eq(extra_vars) expect(params[:skip_tags=]).to eq("packages,migrations,firewall,supervisor") @@ -289,7 +294,7 @@ params = options[:params] inventory_file_contents = File.read(params[:inventory=]) - expect(script_path).to eq("/opt/ansible-installer/setup.sh") + expect(script_path).to eq("ansible-tower-setup") expect(params["--"]).to be_nil expect(params[:extra_vars=]).to eq(extra_vars) expect(params[:skip_tags=]).to eq("packages,migrations,firewall")