Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@mikene_koko

[jinja2] .j2テンプレートファイルのifはスペースを空けないとエラーになる

More than 1 year has passed since last update.

rundeck用のymlファイルを書いていて、通知のところだけ環境ごとに分けたいなーって思ってこんな感じに設定しました。

{{ rundeck.jobs.is_notification }} に、本番環境ならtrueが、その他ならfalseが返ってきて通知の分を出し分けたいって感じです

- description: '15分毎にhogeを実施'
  name: hoge_job
  nodesSelectedByDefault: true
{% if rundeck.jobs.is_notification %}
  notification:
    onfailure:
      plugin:
        configuration:
          webhook_url: {{ rundeck.jobs.notification.slack_webhook }}
        type: SlackNotification
  notifyAvgDurationThreshold: null
{% endif %}
  schedule:
    month: '*'
    time:
      hour: '*'
      minute: '*/15'
      seconds: '0'
    weekday:
      day: '*'
    year: '*'

実行してみるとエラー。 なんだか前の行と一緒にされているみたいです。

TASK [hoge_jobs : exec hoge] ***************************************
fatal: [hoge_ip]: FAILED! => {
  ...
  "stderr": "Error: Jobs Document was invalid for format yaml: mapping values are not allowed here\n in \"<reader>\", line 3, column 3:\n
  "Request failed: 400 Bad Request"
  ...
}

解決方法

結構悩んだのですが、1行空けるだけで解決します。

- description: '15分毎にhogeを実施'
  name: hoge_job
  nodesSelectedByDefault: true

{% if rundeck.jobs.is_notification %}
  notification:
    onfailure:
      plugin:
        configuration:
          webhook_url: {{ rundeck.jobs.notification.slack_webhook }}
        type: SlackNotification
  notifyAvgDurationThreshold: null
{% endif %}

  schedule:
    month: '*'
    time:
      hour: '*'
      minute: '*/15'
      seconds: '0'
    weekday:
      day: '*'
    year: '*'

ymlは改行が挟まっていても読み込めるので見栄えが悪くなる以外は問題ないです。本当にこの解決方法しかないのかな。。。。

一旦これで。

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
mikene_koko
言語絞らずなんでも投稿しているのでカオスです

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?