3
1

More than 1 year has passed since last update.

【Rails×AWS】yamlファイルにおける'please note that yaml must be consistently indented using spaces'の解決

Posted at

https://qiita.com/gyu_outputs/items/b123ef229842d857ff39
こちらの記事を参考にrailsアプリをawsにデプロイする過程で発生したエラーに関する備忘録です。

エラー詳細

ページトップに添付した記事の中の「credentials.ymlの設定」の箇所で直面したエラーです。

credentials.yml
db:
  database: アプリ名
  username: root
  password: 設定したPW
  socket: /var/lib/mysql/mysql.sock

credentials.ymlを記述した後に、

database.yml
production:
  <<: *default
  database: <%= Rails.application.credentials.db[:database] %>
  username: <%= Rails.application.credentials.db[:username] %>
  password: <%= Rails.application.credentials.db[:password] %>
  socket: <%= Rails.application.credentials.db[:socket] %>

上記のようにdatabase.ymlを記述してrspecでテストを実行したところ下記のエラーが発生しました。

RuntimeError:
  YAML syntax error occurred while parsing /Users/hoshiyuunari/Desktop/new_app/selftalk_app/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): found character that cannot start any token while scanning for the next token at line 75 column 13

ちなみに上記エラーコードの「at line 75 column 13」はdatabase.ymlの中では
password: <%= Rails.application.credentials.db[:password] %>
の最初の"<"の部分です。

原因

エラーコード上はインデントの問題とありましたがそうではありませんでした。

database.yml
production:
  <<: *default
  database: <%= Rails.application.credentials.db[:database] %>
  username: <%= Rails.application.credentials.db[:username] %>
  password: "<%= Rails.application.credentials.db[:password] %>" #""をつけただけ
  socket: <%= Rails.application.credentials.db[:socket] %>

credentials.ymlで設定したpasswordの項目が関係していました。
私の場合、パスワードの頭文字が@だったのですがyamlファイルの規則では@には""をつける必要があります。

credentials.ymlではpasswordに""を付けていましたが環境変数として記述する場合も付ける必要がありました。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1