Skip to content

Instantly share code, notes, and snippets.

@willthames
Last active June 19, 2018 04:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save willthames/ee40bd6d9b5eebb9b8eb to your computer and use it in GitHub Desktop.
Save willthames/ee40bd6d9b5eebb9b8eb to your computer and use it in GitHub Desktop.
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