Why am I getting '`parse': (<unknown>): mapping values are not allowed in this context' in YAML file in Ruby
ruby, ruby-2.0, yaml
Solution
Your problem lies in lines which have no colon:
- ps-overture-d01
location: ps-overture-d01
What http://yamllint.com/ does is concatenate them to the next line:
? "ps-overture-d01 location"
: ps-overture-d01
Ruby's YAML library does not do that, but throws an error instead. I'm not sure you meant to have the lines in question concatenated, so you need to see how to properly adjust the YAML to give a sensible structure, perhaps add `id:` to each of those lines?
- id: ps-overture-d01
location: ps-overture-d01
Here is your example, with the change I suggested:
---
servers:
- id: ps-overture-d01
location: ps-overture-d01
tomcat_location: /home/tomcat/tomcat/webapps/report/
user: tomcat
menus:
- id: Accounts Receivable
reports:
- id: Accounts Receivable Aging Report
name: AccountsReceivableAgingReport
location: /public/Common/Reports/Accounts_Receivable_Reports
- id: Inventory
reports:
- id: Inventory Master List Report
name: InventoryMasterListReport
location: /public/Common/Reports/Inventory_Reports
- id: Inventory Totals Report
name: InventoryTotalsReport
location: /public/Common/Reports/Inventory_Reports
- id: Dealer Purchasing Report
name: DealerPurchasingReport
location: /public/Common/Reports/Inventory_Reports
- id: DOA Report
name: DOAReport
location: /public/Common/Reports/Inventory_Reports
- id: Stock Transfers Report
name: StockTransfersReport
location: /public/Common/Reports/Inventory_Reports
- id: Removed Inventory Report
name: RemovedInventoryReport
location: /public/Common/Reports/Inventory_Reports
- id: Inventory Order Sheet Report
name: InventoryOrderSheetReport
location: /public/Common/Reports/Inventory_Reports
- id: Inventory Totals GMROI Report
name: InventoryTotalsGMROIReport
location: /public/Common/Reports/Inventory_Reports
- id: Master Inventory GMROI Report
name: MasterInventoryGMROIReport
location: /public/Common/Reports/Inventory_Reports
- id: Dead Stock Report
name: DeadInventoryReport
location: /public/Common/Reports/Inventory_Reports
- id: Dead Stock Report Details
name: DeadInventoryReportDetails
location: /public/Common/Reports/Inventory_Reports
- id: Negative Quantity Report
name: NegativeInventoryQTYReport
location: /public/Common/Reports/Inventory_Reports
Problem
I am getting the above error when trying to open my Yaml file in Ruby. I have checked the YAML in this validator and it has passed http://yamllint.com/. I'm not sure what could be wrong with my YAML that would be preventing it from opening. Any ideas? Here is the YAML file. I am trying to open the file with `yml = YAML::load(File.open('servers.yml'))` ``` --- servers: - ps-overture-d01 location: ps-overture-d01 tomcat_location: /home/tomcat/tomcat/webapps/report/ user: tomcat menus: - Accounts Receivable reports: - Accounts Receivable Aging Report name: AccountsReceivableAgingReport location: /public/Common/Reports/Accounts_Receivable_Reports - Inventory reports: - Inventory Master List Report name: InventoryMasterListReport location: /public/Common/Reports/Inventory_Reports - Inventory Totals Report name: InventoryTotalsReport location: /public/Common/Reports/Inventory_Reports - Dealer Purchasing Report name: DealerPurchasingReport location: /public/Common/Reports/Inventory_Reports - DOA Report name: DOAReport location: /public/Common/Reports/Inventory_Reports - Stock Transfers Report name: StockTransfersReport location: /public/Common/Reports/Inventory_Reports - Removed Inventory Report name: RemovedInventoryReport location: /public/Common/Reports/Inventory_Reports - Inventory Order Sheet Report name: InventoryOrderSheetReport location: /public/Common/Reports/Inventory_Reports - Inventory Totals GMROI Report name: InventoryTotalsGMROIReport location: /public/Common/Reports/Inventory_Reports - Master Inventory GMROI Report name: MasterInventoryGMROIReport location: /public/Common/Reports/Inventory_Reports - Dead Stock Report name: DeadInventoryReport location: /public/Common/Reports/Inventory_Reports - Dead Stock Report Details name: DeadInventoryReportDetails location: /public/Common/Reports/Inventory_Reports - Negative Quantity Report name: NegativeInventoryQTYReport location: /public/Common/Reports/Inventory_Reports ```