環境
# cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)
# ansible --version
ansible 2.2.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
[CASE1] playbook にローカルホストでの実行を指定する
playbook
- hosts: localhost
connection: local
tasks:
- ping:
hosts
: localhost
を指定
connection
: local
を指定
コマンド実行例
# ansible-playbook sample.yml
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [ping] ********************************************************************
ok: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
[CASE2] ansible-playbook コマンドオプションでローカルホストを指定する
playbook
- hosts: all
tasks:
- ping:
コマンド実行例
# ansible-playbook -i localhost, -c local sample.yml
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [ping] ********************************************************************
ok: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
-i
: localhost,
を指定。","(カンマ)
が必要です。
-c
: local
を指定