Skip to content

Instantly share code, notes, and snippets.

@mogproject
Last active August 29, 2015 14:08
Show Gist options
  • Save mogproject/45df8f8ae48bd3416a6e to your computer and use it in GitHub Desktop.
Save mogproject/45df8f8ae48bd3416a6e to your computer and use it in GitHub Desktop.
Ansible Cheat Sheet

Ansible Cheat Sheet

  • コマンド結果によって処理の要否を判断する
    • register を使ってコマンド実行結果を変数に格納。
    • ignore_errors は必須。changed_when, failed_when は表示を見やすくするために。
- name: check if YOUR_MODULE is installed
  command: /usr/bin/test -e PATH_TO_THE_FILE
  ignore_errors: True
  changed_when: False
  failed_when: False
  register: is_installed
  tags: YOUR_MODULE

- name: install YOUR_MODULE
  ANSIBLE_MODULE: PARAMS
  when: is_installed | failed
  tags: YOUR_MODULE
- name: check if YOUR_PIP_MODULE is installed
  command: pip show YOUR_PIP_MODULE
  ignore_errors: True
  changed_when: False
  failed_when: False
  register: check_installed
  tags: YOUR_PIP_MODULE

- name: install YOUR_PIP_MODULE
  pip: name={{ item }} state=present
  with_items: YOUR_PIP_MODULE_URL
  when: check_installed.stdout == ''
  tags: YOUR_PIP_MODULE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment