2016-12-01 4 views
1

私はリモートでcrontabを展開するはずのcrontabを持っています。しかし、それはいくつかの構文エラーについて不平を言っているようだ。YAMLのフォーマットエラーが発生しました

Ansibleの脚本は、次のとおりです。私は取得しています

--- 
- hosts: cac 
    tasks: 
# - name: Deploy cron to GZIP old log/out files. 
    - cron: 
     name: "Cron entry to gzip rotated log/out files." 
     minute: "0" 
     hour: "*" 
     job: "find /opt/app/log/ -maxdepth 1 \(-name "*out.*[0-9]" -o -name "*.log.[0-9]" \) -type f -size +100M -exec tar -czf {}.tar.gz {} \;" 
     state: present 
     disabled: yes 

エラーは次のようになります。それは私が送信しています仕事を混同いるよう

ERROR! Syntax Error while loading YAML. 


The error appears to have been in '/home/ansible/playbooks/deploy_cac_cron.yaml': line 9, column 69, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

     hour: "*" 
     job: 'find /opt/app/log/ -maxdepth 1 -name '*out.*[0-9]' -o -name '*.log.[0-9]' -type f -size +100M -exec tar -czf {}.tar.gz {} \; ' 
                    ^here 
We could be wrong, but this one looks like it might be an issue with 
unbalanced quotes. If starting a value with a quote, make sure the 
line ends with the same set of quotes. For instance this arbitrary 
example: 

    foo: "bad" "wolf" 

Could be written as: 

    foo: '"bad" "wolf"' 

が見えます。私はここで何ができますか?

答えて

3
あなたは、彼らがあることを意味しているコンパイラに伝えるために外側の二重引用符内に二重引用符( ")をバックスラッシュする必要があります

コマンドの一部です。そうでなければ、コンパイラが次に見ているとすぐに、コマンドの終わりとみなし、残りのステートメントを無効にします。

また、大括弧をバックスラッシュする必要はありません。

私のための働くyamlはここにあります。

- name: Stackoverflow 
    hosts: localhost 
    tasks: 
    - cron: 
     name: "Cron entry to gzip rotated log/out files." 
     minute: "0" 
     hour: "*" 
     job: "find /opt/app/log/ -maxdepth 1 (-name \"*out.*[0-9]\" -o -name \"*.log.[0-9]\") -type f -size +100M -exec tar -czf {}.tar.gz {} ;" 
     state: present 
     disabled: yes 

出力:

[email protected]:~/work/feature/so-playground$ ansible-playbook site.yml 
[WARNING]: provided hosts list is empty, only localhost is available 


PLAY [Stackoverflow] *********************************************************** 

TASK [setup] ******************************************************************* 
ok: [localhost] 

TASK [cron] ******************************************************************** 
changed: [localhost] 

PLAY RECAP ********************************************************************* 
localhost     : ok=2 changed=1 unreachable=0 failed=0 
0

あなたは、これは良いはず

 job: "find /opt/app/log/ -maxdepth 1 \(-name '*out.*[0-9]' -o -name '*.log.[0-9]' \) -type f -size +100M -exec tar -czf {}.tar.gz {} \;" 

を引用して混合しまし

+0

私はこれを試してみました。しかし、それは動作しません。サムエルの答えはうまくいった。ありがとう。 –

関連する問題