From 79a8610030b214dd013f167b66464b79be937f67 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Fri, 24 Jun 2022 12:20:41 +0100 Subject: [PATCH] Support --kolla-playbook argument Adds support for specifying a custom playbook when running Kolla Ansible commands via a '--kolla-playbook' argument. Change-Id: Ie4bba0f1bdc82657572e0f06a71db1140c0bd3a4 --- kayobe/kolla_ansible.py | 11 +++++++++++ kayobe/tests/unit/test_kolla_ansible.py | 4 ++++ .../kolla-ansible-playbook-7e4418ca757e81e8.yaml | 12 ++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 releasenotes/notes/kolla-ansible-playbook-7e4418ca757e81e8.yaml diff --git a/kayobe/kolla_ansible.py b/kayobe/kolla_ansible.py index 6eed88237..8c5532b82 100644 --- a/kayobe/kolla_ansible.py +++ b/kayobe/kolla_ansible.py @@ -56,6 +56,8 @@ def add_args(parser): parser.add_argument("-kl", "--kolla-limit", metavar="SUBSET", help="further limit selected hosts to an additional " "pattern") + parser.add_argument("-kp", "--kolla-playbook", metavar="PLAYBOOK", + help="path to Ansible playbook file") parser.add_argument("--kolla-skip-tags", metavar="TAGS", help="only run plays and tasks whose tags do not " "match these values in Kolla Ansible") @@ -104,6 +106,13 @@ def _validate_args(parsed_args, inventory_filename): parsed_args.kolla_venv, result["message"]) sys.exit(1) + if parsed_args.kolla_playbook: + result = utils.is_readable_file(parsed_args.kolla_playbook) + if not result["result"]: + LOG.error("Kolla Ansible playbook %s is invalid: %s", + parsed_args.kolla_playbook, result["message"]) + sys.exit(1) + def build_args(parsed_args, command, inventory_filename, extra_vars=None, tags=None, verbose_level=None, extra_args=None, limit=None): @@ -113,6 +122,8 @@ def build_args(parsed_args, command, inventory_filename, extra_vars=None, cmd += ["kolla-ansible", command] if verbose_level: cmd += ["-" + "v" * verbose_level] + if parsed_args.kolla_playbook: + cmd += ["--playbook", parsed_args.kolla_playbook] cmd += vault.build_args(parsed_args, "--key") inventory = _get_inventory_path(parsed_args, inventory_filename) cmd += ["--inventory", inventory] diff --git a/kayobe/tests/unit/test_kolla_ansible.py b/kayobe/tests/unit/test_kolla_ansible.py index 6ab0dcd42..8f9650672 100644 --- a/kayobe/tests/unit/test_kolla_ansible.py +++ b/kayobe/tests/unit/test_kolla_ansible.py @@ -61,12 +61,14 @@ class TestCase(unittest.TestCase): "-ki", "/path/to/inventory", "-kl", "host1:host2", "-kt", "tag1,tag2", + "-kp", "/path/to/playbook", ] parsed_args = parser.parse_args(args) kolla_ansible.run(parsed_args, "command", "overcloud") expected_cmd = [ ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&", "kolla-ansible", "command", + "--playbook", "/path/to/playbook", "--inventory", "/path/to/inventory", "--configdir", "/path/to/config", "--passwords", "/path/to/config/passwords.yml", @@ -98,6 +100,7 @@ class TestCase(unittest.TestCase): "--kolla-limit", "host1:host2", "--kolla-skip-tags", "tag3,tag4", "--kolla-tags", "tag1,tag2", + "--kolla-playbook", "/path/to/playbook", ] parsed_args = parser.parse_args(args) mock_run.return_value = "/path/to/kayobe-vault-password-helper" @@ -105,6 +108,7 @@ class TestCase(unittest.TestCase): expected_cmd = [ ".", "/path/to/cwd/venvs/kolla-ansible/bin/activate", "&&", "kolla-ansible", "command", + "--playbook", "/path/to/playbook", "--key", "/path/to/kayobe-vault-password-helper", "--inventory", "/path/to/inventory", "--configdir", "/path/to/config", diff --git a/releasenotes/notes/kolla-ansible-playbook-7e4418ca757e81e8.yaml b/releasenotes/notes/kolla-ansible-playbook-7e4418ca757e81e8.yaml new file mode 100644 index 000000000..77d3f0772 --- /dev/null +++ b/releasenotes/notes/kolla-ansible-playbook-7e4418ca757e81e8.yaml @@ -0,0 +1,12 @@ +--- +features: + - | + Adds support for specifying a custom playbook when running Kolla Ansible + commands via a ``--kolla-playbook`` argument. For example: + + .. code-block:: console + + kayobe overcloud service deploy --kolla-playbook /path/to/playbook.yml + + This may be used to specify a playbook that replaces or extends the default + ``site.yml`` playbook, and needs to execute in the Kolla Ansible context.