My requirement is to run the script stop-all as many times (5 retries) until the output of ps -fu user1 |wc -l becomes less than 2.
I wrote the below ansible playbook for the same:
cat stop.yml
`
hosts: dest_nodes
tasks:
name: Start service
include_tasks: “{{ playbook-dir }}/inner.yml”
retries: 5
delay: 4
until: stopprocesscount.stdout is version(‘2’, ‘<’)
`
cat inner.yml
`
However, I get the below error running the playbook.
`
ERROR! ‘retries’ is not a valid attribute for a TaskInclude
The error appears to be in ‘/app/playbook/stop.yml’: line 19, column 9, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
name: Start service
^ here
`
Can you please suggest?
racke
(Stefan Hornburg)
May 21, 2020, 5:18am
2
My requirement is to run the script stop-all as many times (5 retries) until the output of ps -fu user1 |wc -l becomes
less than 2.
I wrote the below ansible playbook for the same:
cat stop.yml
>
-hosts:dest_nodes
tasks:
-name:Startservice
include_tasks:"{{ playbook-dir }}/inner.yml"
retries:5
delay:4
until:stopprocesscount.stdout isversion('2','<')
>
cat inner.yml
>
-name:Startservice
shell:~/stop-all
register:stopprocess
-name:Startservice
shell:ps -fu user1 |wc -l
register:stopprocesscount
>
However, I get the below error running the playbook.
>
ERROR!'retries'isnota valid attribute fora TaskInclude
Theerror appears to be in'/app/playbook/stop.yml':line 19,column 9,but may
be elsewhere inthe file depending on the exact syntax problem.
Theoffending line appears to be:
-name:Startservice
^here
>
Can you please suggest?
The question is why you don't use one of the various mechanism on a Linux system to ensure
that a process is started or stopped.
Regards
Racke
@Stefan Our service involves a set of processes thus, the start script invokes those several processes and hence the need to count the number of processes using wc -l
to determine if the service (not the process) is running or not.
This sounds all very much like pushing a round peg into a square hole.
I would focus on fine tuning some systemd unit files and their dependencies, instead of the carpet stopping/starting approach.
" ERROR! ‘retries’ is not a valid attribute for a TaskInclude"
Can we use “until” against include_tasks?
Its like we are inserting the same tasks multiple times in the playbook …
Can you use until condition with the actual task itself and check?