###前提・実現したいこと
Ansibleを使って、logrotateの設定ファイル配置と、その前段階としてログファイルのS3へのバックアップ、削除を行おうとしています。
-Cオプションを使って少しずつエラーを解消させていこう、と考えたのですが、メッセージからはどこが問題なのか判断できず…。
取り急ぎ、現在出ているエラーを解消する方法がわかる方がいたらご教示いただけますと幸いです。
※エラーメッセージ、Playbookについてはログ名、パスなど一部改変しています。
おそらくはvarsの使い方、書き方あたりなのかなと推察してはいるのですが…。
また、このエラーが解消したあとはtemplateがうまく使えるかどうかを検証する想定でいます。
###発生している問題・エラーメッセージ
TASK [Backup existing log to S3 with compression] ****************************** fatal: [xxx.xxx.xxx.xxx]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'path'\n\nThe error appears to have been in '/hoge/logrotate.yml': line 8, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Backup existing log to S3 with compression\n ^ here\n"} ...ignoring TASK [Delete logs] ************************************************************* fatal: [xxx.xxx.xxx.xxx]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'path'\n\nThe error appears to have been in '/hoge/logrotate.yml': line 13, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tags: backuplogs\n - name: Delete logs\n ^ here\n"}
###該当のソースコード
lang
1- hosts: hoge 2 vars: 3 logs: 4 - { path: '/path/to/log', logname: 'foo.log', rotation: '3', size: '10M' } 5 - { path: '/path/to/log', logname: 'bar.log', rotation: '3', size: '10M' } 6 - { path: '/path/to/log', logname: 'baz.log', rotation: '5', size: '100M' } 7 tasks: 8 - name: Backup existing log to S3 with compression 9 command: gzip -c {{ item.path }}/{{ item.logname }} | gzip | aws s3 - s3://bucketname/`hostname`/{{ item.logname }}.gz 10 with_items: logs 11 ignore_errors: yes 12 tags: backup_logs 13 - name: Delete logs 14 command: cat /dev/null > {{ item.path }}/{{ item.logname }} 15 with_items: logs 16 tags: delete_logs 17 - name: put config of logrotate 18 template: 19 src: logrotate.j2 20 dest: /etc/logrotate.d/{{ item.logname }} 21 with_items: logs 22 tags: logrotate
※それぞれのタスクにタグをつけているのは1つずつ検証するためです。
また、今回のエラーとは直接関係ないとは思いますが、logrotateのコンフィグのテンプレートは下記のようにして、対象のログファイルごとに設定ファイルを分けて配置する想定です。
{{ item.path }}/{{ item.logname }} { missingok rotate {{ item.rotation }} size {{ item.size }} compress copytruncate }
###試したこと
変数に対してクオーテーションマークをつけたりとかは試してみたのですが、どこが決定的な問題なのかがわかりませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
あるEC2インスタンスから同VPC内の別のEC2インスタンスに対して実施する想定です。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/25 02:30