Esempio n. 1
0
 def test_run_playbooks_failure(self, mock_validate, mock_vars, mock_run):
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     vault.add_args(parser)
     parsed_args = parser.parse_args([])
     mock_run.side_effect = subprocess.CalledProcessError(1, "dummy")
     self.assertRaises(SystemExit, ansible.run_playbooks, parsed_args,
                       ["command"])
Esempio n. 2
0
 def test_run_playbooks_vault_ask_and_file(self, mock_validate, mock_vars,
                                           mock_run):
     mock_vars.return_value = []
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     vault.add_args(parser)
     args = [
         "--ask-vault-pass",
         "--vault-password-file",
         "/path/to/vault/pw",
     ]
     self.assertRaises(SystemExit, parser.parse_args, args)
Esempio n. 3
0
 def test_run_playbooks_all_the_long_args(self, mock_validate, mock_vars,
                                          mock_run):
     mock_vars.return_value = [
         "/path/to/config/vars-file1.yml", "/path/to/config/vars-file2.yaml"
     ]
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     vault.add_args(parser)
     args = [
         "--ask-vault-pass",
         "--become",
         "--check",
         "--config-path",
         "/path/to/config",
         "--extra-vars",
         "ev_name1=ev_value1",
         "--inventory",
         "/path/to/inventory",
         "--limit",
         "group1:host1",
         "--skip-tags",
         "tag3,tag4",
         "--tags",
         "tag1,tag2",
         "--list-tasks",
     ]
     parsed_args = parser.parse_args(args)
     ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"])
     expected_cmd = [
         "ansible-playbook",
         "--list-tasks",
         "--ask-vault-pass",
         "--inventory",
         "/path/to/inventory",
         "-e",
         "@/path/to/config/vars-file1.yml",
         "-e",
         "@/path/to/config/vars-file2.yaml",
         "-e",
         "ev_name1=ev_value1",
         "--become",
         "--check",
         "--limit",
         "group1:host1",
         "--skip-tags",
         "tag3,tag4",
         "--tags",
         "tag1,tag2",
         "playbook1.yml",
         "playbook2.yml",
     ]
     mock_run.assert_called_once_with(expected_cmd, quiet=False)
     mock_vars.assert_called_once_with("/path/to/config")
Esempio n. 4
0
 def test_run_playbooks_func_args(self, mock_validate, mock_vars, mock_run):
     mock_vars.return_value = [
         "/etc/java_role/vars-file1.yml", "/etc/java_role/vars-file2.yaml"
     ]
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     vault.add_args(parser)
     args = [
         "--extra-vars",
         "ev_name1=ev_value1",
         "--limit",
         "group1:host1",
         "--tags",
         "tag1,tag2",
     ]
     parsed_args = parser.parse_args(args)
     kwargs = {
         "extra_vars": {
             "ev_name2": "ev_value2"
         },
         "limit": "group2:host2",
         "tags": "tag3,tag4",
         "verbose_level": 0,
         "check": True,
     }
     ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"],
                           **kwargs)
     expected_cmd = [
         "ansible-playbook",
         "--inventory",
         "/etc/java_role/inventory",
         "-e",
         "@/etc/java_role/vars-file1.yml",
         "-e",
         "@/etc/java_role/vars-file2.yaml",
         "-e",
         "ev_name1=ev_value1",
         "-e",
         "ev_name2=ev_value2",
         "--check",
         "--limit",
         "group1:host1:&group2:host2",
         "--tags",
         "tag1,tag2,tag3,tag4",
         "playbook1.yml",
         "playbook2.yml",
     ]
     mock_run.assert_called_once_with(expected_cmd, quiet=False)
     mock_vars.assert_called_once_with("/etc/java_role")
Esempio n. 5
0
 def test_run_playbooks_vault_password_helper(self, mock_validate,
                                              mock_vars, mock_run):
     mock_vars.return_value = []
     parser = argparse.ArgumentParser()
     mock_run.return_value = "/path/to/java_role-vault-password-helper"
     ansible.add_args(parser)
     vault.add_args(parser)
     mock_run.assert_called_once_with(
         ["which", "java_role-vault-password-helper"], check_output=True)
     mock_run.reset_mock()
     parsed_args = parser.parse_args([])
     ansible.run_playbooks(parsed_args, ["playbook1.yml"])
     expected_cmd = [
         "ansible-playbook",
         "--vault-password-file",
         "/path/to/java_role-vault-password-helper",
         "--inventory",
         "/etc/java_role/inventory",
         "playbook1.yml",
     ]
     mock_run.assert_called_once_with(expected_cmd, quiet=False)
Esempio n. 6
0
 def test_run_playbooks_vault_password_file(self, mock_validate, mock_vars,
                                            mock_run):
     mock_vars.return_value = []
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     vault.add_args(parser)
     args = [
         "--vault-password-file",
         "/path/to/vault/pw",
     ]
     parsed_args = parser.parse_args(args)
     ansible.run_playbooks(parsed_args, ["playbook1.yml"])
     expected_cmd = [
         "ansible-playbook",
         "--vault-password-file",
         "/path/to/vault/pw",
         "--inventory",
         "/etc/java_role/inventory",
         "playbook1.yml",
     ]
     mock_run.assert_called_once_with(expected_cmd, quiet=False)
Esempio n. 7
0
 def test_run_playbooks(self, mock_validate, mock_vars, mock_run):
     mock_vars.return_value = [
         "/etc/java_role/vars-file1.yml", "/etc/java_role/vars-file2.yaml"
     ]
     parser = argparse.ArgumentParser()
     ansible.add_args(parser)
     vault.add_args(parser)
     parsed_args = parser.parse_args([])
     ansible.run_playbooks(parsed_args, ["playbook1.yml", "playbook2.yml"])
     expected_cmd = [
         "ansible-playbook",
         "--inventory",
         "/etc/java_role/inventory",
         "-e",
         "@/etc/java_role/vars-file1.yml",
         "-e",
         "@/etc/java_role/vars-file2.yaml",
         "playbook1.yml",
         "playbook2.yml",
     ]
     mock_run.assert_called_once_with(expected_cmd, quiet=False)
     mock_vars.assert_called_once_with("/etc/java_role")