私はいくつかのローカルブックで意味をなさないプレイブックを持っています。そうでなければ、リモートで実行されます。私はdelegate_to
ディレクティブを使用しますが、それはまた、例えば、私はすべての私の仕事を倍増しなければならないことを意味:条件付きでdelegate_toローカルまたはリモートですか?
---
- hosts: all
gather_facts: no
tasks:
- name: Local command
command: hostname
register: target_host
when: vhost is undefined
delegate_to: 127.0.0.1
# ---
- name: Remote command
command: hostname
register: target_host
when: vhost is defined
Execのローカルにあることを行うために:
$ ansible-playbook -i inv.d/test.ini play.d/delegate.yml
PLAY [all] ********************************************************************
TASK: [Local command] *********************************************************
changed: [new-server -> 127.0.0.1]
TASK: [Remote command] ********************************************************
skipping: [new-server]
PLAY RECAP ********************************************************************
new-server : ok=1 changed=1 unreachable=0 failed=0
Execのリモートで:
$ ansible-playbook -i inv.d/test.ini play.d/delegate.yml -e vhost=y
PLAY [all] ********************************************************************
TASK: [Local command] *********************************************************
skipping: [new-server]
TASK: [Remote command] ********************************************************
changed: [new-server]
PLAY RECAP ********************************************************************
new-server : ok=1 changed=1 unreachable=0 failed=0
ansible
ローカル環境にフォールバックするときにはよりスマートな方法がありますか?現在、私はansible==1.9.2
を使用しています。
'connection:" {{'ansible_host' | default( 'local')}} ''? [Docs](http://docs.ansible.com/ansible/intro_inventory.html#non-ssh-connection-types)はあいまいであるように見えますが、 'ansible_host'は'接続するDockerコンテナの名前 'として定義されています。私は喜んでそれはドキュメントの単なるエラーです。 –
このセクションの下部に記載されているように、インベントリファイルに接続を設定します:http://docs.ansible.com/ansible/intro_inventory.html#hosts-and-groups – udondan
'localhost ansible_connection = local' – udondan