launching different comands on different servers
I want to stop system on several servers. I have two types of servers insert and storages.
on servers with tag insert i need to run command systemctl stop vm-insert and on storages systemctl stop vm-storage
i've made such config
tasks:
stop-vm-insert:
cmd: |
echo "systemctl stop vm-insert";
....
target:
tags: [insert]
stop-vm-storage:
cmd: |
echo "systemctl stop vm-storage";
....
target:
tags: [ storage ]
stop-daemons:
tasks:
- task: stop-vm-insert
- task: stop-vm-storage
i'm expecting that commands must be issued only on target servers but instead they are run on both target groups.
Any ideas on how to do so ?
The current task logic doesn't support your code yet, but there's a way to do it:
- one involves some bash scripting
- and the other one invokes the two tasks manually.
I know what you're aiming at here, and when I start working on enhancing the tasks logic I'll keep this workflow in mind (will keep the issue open as well). Currently targets only work for the root task (the task you invoke when you run sake run <task>, this is because tasks can be nested, and so it becomes unclear which tags will take precedence.
1.
via server environment variable tags:
tasks:
stop-vm-insert:
cmd: |
if [[ $SAKE_SERVER_TAGS == *"insert"* ]];
then
echo "systemctl stop vm-insert";
fi
stop-vm-storage:
cmd: |
if [[ $SAKE_SERVER_TAGS == *"insert"* ]];
then
echo "systemctl stop vm-storage";
fi
stop-daemons:
target:
all: true
tasks:
- task: stop-vm-insert
- task: stop-vm-storage
and run sake run stop-daemons.
2.
Or:
stop-vm-insert:
target:
tags: [insert]
cmd: |
echo "systemctl stop vm-insert";
stop-vm-storage:
target:
tags: [storage]
cmd: |
echo "systemctl stop vm-storage";
and run sake run stop-vm-insert stop-vm-storage
Oh tnx! looks like option 2 is fine enough :)