helen's blog

ぽんこつによるぽんこつのためのぽんこつブログ

ansible2系の諸々

ansibleのプルリク見てて気になったのでめも

2系インストールとバージョン確認

$ sudo yum install ansible
$ ansible --version
ansible 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

sudoで怒られたとき

$ ansible-playbook -i localhost playbook.yml --syntax-check
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method is 'sudo' (default).
This feature will be removed in a future release. 
Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
For those from Pre 1.9 , sudo and su still work!

For those using old playbooks will not need to be changed,
even though they are deprecated, sudo and su directives, variables and options will continue to work. 
It is recommended to move to become as they may be retired at one point. 
You cannot mix directives on the same object (become and sudo) though, Ansible will complain if you try to.

Become will default to using the old sudo/su configs and variables if they exist,
but will override them if you specify any of the new ones.

Become (Privilege Escalation) — Ansible Documentation

sudoがそのうちなくなるのでbecomeを使った用がいいよ!とのこと

sudo, becomeとは
  • ansibleの実行ユーザーを変える
  • yesでplaybook全体がsudoになる
  • noでansibleの接続ユーザ権限で実行

bare variablesで怒られたとき

[DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full variable
syntax ('{{hoge}}').
This feature will be removed in a future release. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.

変数を

'{{hoge}}'

みたいに囲みましょうとのこと

Loops — Ansible Documentation

dry runしたいとき

コマンドに-Cオプションをつける
ドライランなのでansibleでインストールして実行するものはエラーする

# 例
$ ansible-playbook -i localhost playbook.yml -C

エラーで止まらず進み続けたいとき

playboolに下記追記

ignore_errors: True