Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Demo of pkill behaviour with Ansible
[will@fedora pkilldemo]$ ansible-playbook pkilldemo.yml
PLAY [localhost] **************************************************************
GATHERING FACTS ***************************************************************
ok: [127.0.0.1]
TASK: [generate random process string] ****************************************
changed: [127.0.0.1]
TASK: [warn user] *************************************************************
[127.0.0.1]
About to kill processes matching lkSm/8UMTb9bR2ZharCU with signal SIGIO. Hit Return to continue or Ctrl-C then a to abort:
ok: [127.0.0.1]
TASK: [show bad effects of pkill -f] ******************************************
changed: [127.0.0.1]
TASK: [works ok without -f] ***************************************************
changed: [127.0.0.1]
TASK: [works ok with pgrep -f] ************************************************
changed: [127.0.0.1]
TASK: [this is supposed to fail as we don't handle the error with true] *******
failed: [127.0.0.1] => {"changed": true, "cmd": "pgrep -f lkSm/8UMTb9bR2ZharCU ", "delta": "0:00:00.023586", "end": "2014-05-28 21:00:54.400289", "rc": 1, "start": "2014-05-28 21:00:54.376703"}
...ignoring
- hosts: localhost
connection: local
tasks:
- name: generate random process string
action: shell openssl rand 15 | base64
register: process_string
- name: warn user
pause: prompt="About to kill processes matching {{process_string.stdout}} with signal SIGIO. Hit Return to continue or Ctrl-C then a to abort"
- name: show bad effects of pkill -f
action: shell pkill -IO -f {{process_string.stdout}} || true
ignore_errors: True
- name: works ok without -f
action: shell pkill -IO {{process_string.stdout}} || true
- name: works ok with pgrep -f
action: shell pgrep -f {{process_string.stdout}} || true
- name: this is supposed to fail as we don't handle the error with true
action: shell pgrep -f {{process_string.stdout}}
ignore_errors: True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment