Under my Playbook , i want to run a shell command which is the following :
for STACK in stackone stacktwo;do docker stack ps --format "table {{.ID}}\t{{.Name}}\t{{.CurrentState}}\t{{.Error}}\t{{.Node}}" $STACK | (read -r; printf "%s\n" "$REPLY"; sort -k 2|grep srcd |grep -v Shutdown ); done;
As you can see my shell command is quite complex , so when i am running it like this , it fails throwing always syntax errors
- name : Check running services
shell: for STACK in stackone srcd-pilote;do docker stack ps --format "table {{.ID}}\t{{.Name}}\t{{.CurrentState}}\t{{.Error}}\t{{.Node}}" $STACK | (read -r; printf "%s\n" "$REPLY"; sort -k 2|grep srcd |grep -v Shutdown ); done;
register: result
I see there is many characters which need to be passed as strings such as {{.Name}} and |grep ...
So i ve tried this :
- name : Check running services
shell: "for STACK in srcd-current stacktwo;do docker stack ps --format 'table {{'"{{.ID}}"'}}\t{{'"{{.Name}}"'}}\t{{'"{{.CurrentState}}"'}}\t{{'"{{.Error}}"'}}\t{{'"{{.Node}}"'}}' $STACK | (read -r; printf '%s\n' '$REPLY'; sort -k 2'"{{|}}"'grep srcd '"{{|}}"'grep -v Shutdown ); done; "
register: result
But it stills failing .
Suggesstions ??