Skip to content

rewrite deploy.py so differently names roles and tags actually run#557

Open
KoenDR06 wants to merge 2 commits into
masterfrom
deploy-rewrite
Open

rewrite deploy.py so differently names roles and tags actually run#557
KoenDR06 wants to merge 2 commits into
masterfrom
deploy-rewrite

Conversation

@KoenDR06

@KoenDR06 KoenDR06 commented May 8, 2026

Copy link
Copy Markdown
Contributor

Also closes (#481)

@SilasPeters SilasPeters left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure why you rewrote everything. The old system was less verbose and fine right? Not sure what logic has improved from reading it once.

Edit: the --skip feature is nice though and needed

Comment thread ansible/deploy.py
roles = roles[roles.index(from_playbook) :]
from_until = True
# ... we will filter this
role_data = [it for it in all_role_data]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can be made a list()

Comment thread ansible/deploy.py
)
@click.option("--tags", "--roles", help="Roles to execute")
@click.option("--roles", help="Roles to execute")
@click.option("--skip", help="Roles to skip")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would rename this to exclude, since --from seems ambigious with --skip

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lol my original idea was skip but I now prefer exclude

Comment thread ansible/deploy.py
from_until = True
# ... we will filter this
role_data = [it for it in all_role_data]
all_roles = [it["role"] for it in all_role_data]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

perhaps use map()? More verbose but more intuitive

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, rename to role_names

Comment thread ansible/deploy.py
@click.option("--force", is_flag=True, default=False, help="Override checks")
@click.option(
"--from",
"from_playbook",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I now realise someone confused playbooks with roles, and as such from_playbook is a wrong synonym and should be removed. Same as until_playbook. from_playbook (used later) should be renamed to from_role

Comment thread ansible/deploy.py

### Filter out all roles that fall outside specified range
i = 0
if from_playbook is not None and from_playbook in all_roles:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So please rename from_playbook to from_role

Comment thread ansible/deploy.py
Comment on lines +112 to +124
if from_playbook is not None and from_playbook in all_roles:
i = all_roles.index(from_playbook)
role_data = role_data[i:]
if until_playbook is not None and until_playbook in all_roles:
# We have to subtract i to correct for offset
i = all_roles.index(until_playbook) - i
if i < 0:
raise IndexError("`--until` role must be after the `--from` role")
role_data = role_data[: i + 1]

### If we didn't specify from or until, clear data
if from_playbook is None and until_playbook is None:
role_data = []

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if it is not in all_roles? These if statements are nonexhaustive thus creating edge cases where the code continues but the argument is incorrect.
Or to put it more concretely, if I say --from kaas all roles are used but I indended --from koala and I dont get an error so I assume everything starts from koala

Comment thread ansible/deploy.py
Comment on lines +134 to +145
if roles is not None:
for role in roles.split(","):
role = role.strip()
role = next(filter(lambda x: x["role"] == role, all_role_data))
role_data.append(role)

### Exclude roles from --skip
if skip is not None:
for role in skip.split(","):
role = role.strip()
role_data = list(filter(lambda x: x["role"] != role, role_data))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if role is not in the list? Please check beforehand if all mentioned items are in the list of known roles

Comment thread ansible/deploy.py
Comment on lines +123 to +124
if from_playbook is None and until_playbook is None:
role_data = []

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we reset the list to empty? Shouldn't we use all roles, and as such just keep it as is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants