Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for skip_tags #166

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions etc/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ tasks:
tags:
- tag_false

- name: skip_task_tagged_task_false
play_items:
- run_bin
allowed_for:
- acl_group: root_on_testing_in_testInfra_testInfra2
allow_limit: False
skip_tags:
- tag_false

- name: task_skipping
play_items:
- run_skippable
Expand Down
4 changes: 4 additions & 0 deletions source/modules/configs/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@
"tags": {
"type": "list",
"required": False
},
"skip_tags": {
"type": "list",
"required": False
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions source/modules/runners/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,24 @@ def run_playitem(self, config: dict, options: dict, inventory: str, lockpath: st
def get_tags_for_task(config: dict, options: dict):
"""Function to get task's tags"""
tags = []
skip_tags = []
for task in config["tasks"]["tasks"]:
if task["name"] == options["task"]:
tags = task.get("tags", [])

if options["dry_mode"]:
tags.append("ansible_deployer_dry_mode")

return tags
for task in config["tasks"]["tasks"]:
if task["name"] == options["task"]:
skip_tags = task.get("skip_tags", [])

return tags, skip_tags

@staticmethod
def construct_command(playitem: str, inventory: str, config: dict, options: dict):
"""Create final ansible command from available variables"""
tags = Runners.get_tags_for_task(config, options)
tags, skip_tags = Runners.get_tags_for_task(config, options)

if "runner" in playitem and playitem["runner"] == "py.test":
command = ["py.test", "--ansible-inventory", inventory]
Expand All @@ -213,6 +218,9 @@ def construct_command(playitem: str, inventory: str, config: dict, options: dict
if tags:
command.append("-t")
command.append(",".join(tags))
if skip_tags:
command.append("--skip-tags")
command.append(",".join(skip_tags))
if options["check_mode"]:
command.append("-C")
command_env=dict(os.environ, ANSIBLE_STDOUT_CALLBACK="yaml", ANSIBLE_NOCOWS="1",
Expand Down
2 changes: 2 additions & 0 deletions tests/02a-checkrun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ check_run_ok "ansible-deployer run --task task_exec_bin_true --stage prod --infr
check_run_ok "ansible-deployer run --task task_with_limit --stage testing --infrastructure testInfra --limit testHost1"
check_run_ok "ansible-deployer run --task tagged_task_true --stage testing --infrastructure testInfra"
check_run_ok "ansible-deployer verify --task task_exec_bin_true --stage prod --infrastructure testInfra"
check_run_ok "ansible-deployer run --task skip_task_tagged_task_false --stage testing --infrastructure testInfra"
check_run_fail "ansible-deployer run --task tagged_task_false --stage testing --infrastructure testInfra"

echo -e " ___ ____ _ _\n / _ \___ \ __ _ ___| |__ ___ ___| | ___ __ _ _ _ __\n | | | |__) / _\` | _____ / __| '_ \ / _ \/ __| |/ / '__| | | | '_ \ \n | |_| / __/ (_| | |_____| | (__| | | | __/ (__| <| | | |_| | | | |\n \___/_____\__,_| \___|_| |_|\___|\___|_|\_\_| \__,_|_| |_|\n \n _ _ _ _ _ _\n (_)_ ____ ____ _| (_) __| | ___ _ __ | |_(_) ___ _ __ ___\n | | '_ \ \ / / _\` | | |/ _\` | / _ \| '_ \| __| |/ _ \| '_ \/ __|\n | | | | \ V / (_| | | | (_| | | (_) | |_) | |_| | (_) | | | \__ \ \n |_|_| |_|\_/ \__,_|_|_|\__,_| \___/| .__/ \__|_|\___/|_| |_|___/\n |_|\n"
# Non-existent option values
Expand Down
16 changes: 16 additions & 0 deletions tests/testing_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ check_run_ok() {
fi
}

check_run_fail() {
CMD=$1
echo "Check: $CMD"
$CMD
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

squash

if [ $? -eq 0 ]
then
echo "FAILED(Expected failure got return code of 0): ${CMD}"
echo "$CMD"
eval "$CMD"
exit 1
else
echo "OK - failed as expected"
fi
}


Copy link
Collaborator

@LegenJCdary LegenJCdary Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

check_message_in_output() {
CMD=$1
EXPTEXT=$2
Expand Down