2017-06-21 7 views
0

でそれを使用:Ansibleレジスタcheck_pathと私はサイトの以下のハッシュ/ dictの構造持つwith_dictループ

sites: 
    example.com: 
    site: example.com 
    mail: [email protected] 
    site_alias: www.example.com 
    example.fi: 
    site: example.fi 
    mail: [email protected] 
    site_alias: example.fi 

を...

もがあれば、私は、すべてのサイトのためのレジスタ値それのためのフォルダ。結果を印刷します。

name: "Check if path already exists so it is the first time." 
    stat: path={{ cert_files }}/{{ item.value.site }} 
    register: check_path 
    with_dict: "{{ sites }}" 
debug: var=check_path.results 
# No need to print the whole dictionary, all results are already there. 
# with_dict: "{{ sites }}" 

だから私のようなものを得る:

TASK [letsencrypt : debug]  ***************************************************** 
ok: [78.47.67.114] => (item={'key': u'example.com', 'value': {u'mail': u'[email protected]', u'site_alias': u'www.example.com', u'site': u'example.com'}}) => { 
"check_path.results": [ 
    { 
     "_ansible_item_result": true, 
     "_ansible_no_log": false, 
     "_ansible_parsed": true, 
     "changed": false, 
     "invocation": { 
      "module_args": { 
       "checksum_algorithm": "sha1", 
       "follow": false, 
       "get_checksum": true, 
       "get_md5": true, 
       "mime": false, 
       "path": "/etc/letsencrypt/live/example.com" 
      }, 
      "module_name": "stat" 
     }, 
     "item": { 
      "key": "example.com", 
      "value": { 
       "mail": "[email protected]", 
       "site": "example.com", 
       "site_alias": "www.example.com" 
      } 
     }, 
     "stat": { 
      "atime": 147869032.3522692, 
      "ctime": 149636484.0226028, 
      "dev": 2049, 
      "executable": true, 
      "exists": true, 
      "gid": 0, 
      "gr_name": "root", 
      "inode": 15725, 
      "isblk": false, 
      "ischr": false, 
      "isdir": true, 
      "isfifo": false, 
      "isgid": false, 
      "islnk": false, 
      "isreg": false, 
      "issock": false, 
      "isuid": false, 
      "mode": "0755", 
      "mtime": 14632684.026028, 
      "nlink": 2, 
      "path": "/etc/letsencrypt/live/example.com", 
      "pw_name": "root", 
      "readable": true, 
      "rgrp": true, 
      "roth": true, 
      "rusr": true, 
      "size": 4096, 
      "uid": 0, 
      "wgrp": false, 
      "woth": false, 
      "writeable": true, 
      "wusr": true, 
      "xgrp": true, 
      "xoth": true, 
      "xusr": true 
     } 
    }, 
    { 
     "_ansible_item_result": true, 
     "_ansible_no_log": false, 
     "_ansible_parsed": true, 
     "changed": false, 
     "invocation": { 
      "module_args": { 
       "checksum_algorithm": "sha1", 
       "follow": false, 
       "get_checksum": true, 
       "get_md5": true, 
       "mime": false, 
       "path": "/etc/letsencrypt/live/example.com" 
      }, 
      "module_name": "stat" 
     }, 
     "item": { 
      "key": "example.fi", 
      "value": { 
       "mail": "[email protected]", 
       "site": "example.fi", 
       "site_alias": "www.example.fi" 
      } 
     }, 
     "stat": { 
      "atime": 1493734857.9738503, 
      "ctime": 1485960159.8090317, 
      "dev": 2049, 
      "executable": true, 
      "exists": true, 

どのように使用するか、値を取得する「check_path.results.stats.exists」次のタスクの最後の値Iが反復する場合することができますが{{sites}}まで

私はこのような何かを成功させようとしました。

- name: Make a certificate the first time. 
    command: /bin/bash /opt/letsencrypt/letsencrypt-auto certonly -- standalone --email "{{ item.value.mail }}" --agree-tos --keep-until- expiring -d "{{ item.value.site }}" -d "{{ item.value.site_alias }}" 
    with_items: check_path 
    when: check_path.results.stat.exists == false 

または

- name: Make a certificate the first time. 
    command: /bin/bash /opt/letsencrypt/letsencrypt-auto certonly standalone --email "{{ item.value.mail }}" --agree-tos --keep-until-expiring -d "{{ item.value.site }}" -d "{{ item.value.site_alias }}" 
    with_dict: "{{ sites }}" 
    when: check_path.results.stat.exists == false 

答えて

1

あなたはいない元のリストの上に、結果を反復処理する必要があります

- name: Make a certificate the first time. 
    command: /bin/bash /opt/letsencrypt/letsencrypt-auto certonly standalone --email "{{ item.item.value.mail }}" --agree-tos --keep-until-expiring -d "{{ item.item.value.site }}" -d "{{ item.item.value.site_alias }}" 
    with_items: "{{ check_path.results }}" 
    when: not item.stat.exists 

ここitem.itemは、元のリストの項目です。

+0

これはまさにそのように機能します!ありがとうございました! – TipiT

関連する問題