Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add support of task's targets set directly in playbook #85

Merged
merged 1 commit into from
May 12, 2023
Merged

Conversation

umputun
Copy link
Owner

@umputun umputun commented May 12, 2023

Add new task-level filed targets.

It will be used only in case no -t/--target is set in the command line. Technically, -t always set as it has a default target default; however, this PR considers such default as non-set and will use task.targets

This is what it looks like in the playbook:

targets:
  prod:
    hosts: [{host: "h1.example.com", user: "test"}, {"h2.example.com", "port": 2222, name: "h2"}]
  staging:
    groups: ["staging"]

tasks:
  - name: task1
    targets: ["dev", "host3.example.com:2222"]
    commands:
      - name: command1
        script: echo "Hello World."

targets inside the task resolved the same way as targets defined in the command line, i.e. all the sequence of matching groups, tags, names, etc...

The reason why this may be handy is the ability to make a playbook with multiple tasks where all the tasks are sort of related but should be running on a different subset of hosts. For instance, one task deploys changes to the master/controller boxes, and another task deploys to working nodes.

Before this change, It was possible to run the spot twice for different task with different targets or even different playbooks. However, for related tasks, it is very nice to have a single spot run dealing with everything

@umputun umputun merged commit 2ffd159 into master May 12, 2023
@umputun umputun deleted the task_hosts branch May 12, 2023 01:23
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.

None yet

1 participant