2016-09-29 3 views
0

リモートホストからファイルを取得しようとしています。しかし、stackoverflowの上のいくつかの例を見た後、下の2つの方法がフォローエラーが発生:可能性があるフェッチ引用符エラー

- shell: ls -f ubuntu_s* 
    register: file_name 
- fetch: src=/home/ubuntu/{{file_name.stdout_lines}} dest=/home/user 


- shell: ls -f ubuntu_s* 
     register: file_name 
    - fetch: src={{item}} dest=/home/user 
     with_items: "{{file_name.stdout_lines}}" 

エラー:

ERROR! this task 'fetch' has extra params, which is only allowed in the following modules: command, shell, script, include, include_vars, add_host, group_by, set_fact, raw, meta 

The error appears to have been in '/home/user/BuildPkg.yml': line 49, column 7, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

     register: file_name 
    - fetch: src=/home/ubuntu/{{file_name.stdout_lines}} dest=/home/user 
    ^here 
We could be wrong, but this one looks like it might be an issue with 
missing quotes. Always quote template expression brackets when they 
start a value. For instance: 

    with_items: 
     - {{ foo }} 

Should be written as: 

    with_items: 
     - "{{ foo }}" 


The error appears to have been in '/home/user/BuildPkg.yml': line 49, column 7, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

     register: file_name 
    - fetch: src=/home/ubuntu/{{file_name.stdout_lines}} dest=/home/user 
    ^here 
We could be wrong, but this one looks like it might be an issue with 
missing quotes. Always quote template expression brackets when they 
start a value. For instance: 

    with_items: 
     - {{ foo }} 

Should be written as: 

    with_items: 
     - "{{ foo }}" 

両方のアプローチは、同じエラーを与えます。何が間違っているようですか?

答えて

2

を解析しようとするたびにknow what you may face

- fetch: src={{ item }} dest=/home/user 
    with_fileglob: 
    - ubuntu_s* 

注意を。モジュール - これは不可解な方法です。
リモートホストからのファイルのリストを取得し、それらをフェッチする必要がある場合:

- find: 
    pattern: ubuntu_s* 
    path: /home/ubuntu/ 
    register: myfiles 
- fetch: 
    src: "{{ item.path }}" 
    dest: /home/user 
    flat: yes 
    with_items: "{{ myfiles.files }}" 
+0

これはうまくいった!あなたが大きなファイルを転送したいのであれば、ちょうどノートになるでしょう:これにはnoを付けてください – latencybit

+0

大ファイルの@latencybitまた 'synchronize'モジュールもあります –

1

正しい方法は次のように、ファイルグロブをループさ:shell可能な場合を避けるようにしてくださいlsの出力

+0

を私はまだコマンドを登録し、シェルが必要なのでしょうか? – latencybit

+0

nope、ちょうど上記のもの –

+2

'with_fileglob'が**ローカルで拡張されていること注意してください**!これは、リモートホストからのファイルのリストを収集するためには機能しません。 –

関連する問題