web-dev-qa-db-ja.com

Ansible1.6には非推奨のwith_itemsが含まれています

したがって、この機能は非推奨になっているようです。理由はよくわかりません。AnsibleCTOは、代わりにwith_nestedを使用する必要があると言っていますが、正直なところ、その方法がわかりません。

これが私のプレイブークです:

- hosts: all
  user: root
  vars: 
   - sites:
     - site: site1.com
       repo: ssh://[email protected]/orgname/reponame
       nginx_ssl: true;
       copy_init:
        - path1/file1.txt
        - path2/file2.php
        - path2/file3.php

     - site: site2.net
       repo: ssh://[email protected]/orgname/reposite2

     - site: site4.com
       repo: ssh://[email protected]/orgname/reposite3
       copy_init:
        - path2/file2.php

  tasks:
     - name: Bootstrap Sites
      include: bootstrap_site.yml site={{item}}

そして、Ansible1.6.6でこれを実行しようとしたときのエラーメッセージ:

エラー:[非推奨]:include + with_itemsは削除された非推奨の機能です。プレイブックを更新してください。

このプレイブックをこのansibleバージョンで動作するものに変換するにはどうすればよいですか?

17
jmserra

残念ながら、ドロップインの代替品はありません。あなたができるいくつかのこと:

  • 含まれているファイルにリストを渡し、そこで繰り返します。あなたのプレイブック:

    vars:
        sites:
           - site1
           - site2
    tasks:
        - include: bootstrap_site.yml sites={{sites}}
    

    そしてbootstrap_site.ymlで:

    - some_Task: ...
      with_items: sites
    
    - another_task: ...
      with_items: sites
    
    ...
    
  • Bootstrap_siteを module (python、bashなど)として書き直し、プレイブックの横のlibraryディレクトリに配置します。次に、次のことができます。

    - bootstrap_site: site={{item}}
      with_items: sites
    

更新:Ansible V2がリリースされ、include + with_items コンボループ が返されます!

21
hkariti

元の投稿で尋ねられたように、私は何とか非推奨のメッセージを回避するための答えを見つけました。

ファイルvars/filenames.ymlを追加しました:

  filenames:
  - file1
  - file2
  - file3

次に、プレイブックの冒頭でこれらの名前を読みました。

  - name: read filenames
    include_vars: vars/filenames.yml

その後、後で使用できます。

  - name: Copy files 1
    copy: src=/filesrc1/{{ item }} dest=/filedest1/{{ item }} owner=me group=we
    with_items: filenames

等々....

よろしく、トム

1