2016-05-23 5 views
2

私は2.1を使用しています。私はdelegate_toを使用してホストグループにコマンドを実行したいと思います。他のホストへの委任可能

[[email protected] control]# ansible-playbook -i inventory test.yml 

PLAY *************************************************************************** 

TASK [setup] ******************************************************************* 
ok: [ansible] 

TASK [debug] ******************************************************************* 
ok: [ansible] => { 
    "groups.cls": [ 
     "cls-host-1", 
     "cls-host-2" 
    ] 
} 

TASK [touch a file to running host] ******************************************** 
changed: [ansible -> cls-host-1] => (item=cls-host-1) 
changed: [ansible -> cls-host-2] => (item=cls-host-2) 

PLAY RECAP ********************************************************************* 
ansible     : ok=3 changed=1 unreachable=0 failed=0 

が、タッチのみ行われます。 私は

--- 
- hosts: ansible 
# gather_facts: yes 

    tasks: 
    - debug: var=groups.cls 

    - name: touch a file to running host 
    shell: echo {{ item }} >> /tmp/{{ inventory_hostname }} 
    delegate_to: "{{ item }}" 
    with_items: "{{ groups.cls }}" 
出力と

次している私は、ホストのparamとしてlocalhostを使用して、私はCLSホストの両方に「タッチ」コマンドを委任したいです最初のホスト:

[[email protected] ~]# more /tmp/ansible 
cls-host-1 
cls-host-2 

何か問題がありますか?他の方法でコマンドを委任できますか?

私はAnsible 2.4.0.0を使用して、脚本のバリエーションをテストしてみた
+0

代わりに 'with_items:groups.cls'を試してください。 – sap1ens

+0

with_items:groups.clsを試しています:[DEPRECATION WARNING]:ベア変数の使用は非推奨です。環境変数が完全な変数構文( '{{groups.cls}')を使用するように、プレイブックを更新します。この機能は、将来のリリースで削除される予定です。使用可能なcffファイルで deprecation_warnings = Falseを設定すると、非推奨の警告を無効にすることができます。 –

答えて

0

#!/usr/bin/env ansible-playbook 

- hosts: stretch.fritz.box 
    tasks: 
    - name: touch 
    shell: echo {{item}} >>/tmp/{{inventory_hostname}} 
    delegate_to: "{{item}}" 
    with_items: 
     - jessie.fritz.box 
     - short.fritz.box 

これが正常に動作している:タッチは、ジェシーと短い

jessie$ cat /tmp/stretch.fritz.box 
jessie.fritz.box 

short$ cat /tmp/stretch.fritz.box 
short.fritz.box 

上で実行され、おそらくこの機能をされました2.1と2.4の間でAnsibleに導入されました。