In OpsWorks, I'm trying to test the number suffix on a hostname of a given node, and to extract that number if it isn't 1. If the number isn't 1, I have this regex to match the number:
Which is run against a node naming scheme that follows this pattern:
I've verified this works using Rubular: http://rubular.com/r/Ei0kqjaxQn
However, when I run this against an instance with OpsWorks, this match returns nil, no matter what number the hostname has at the end. The OpsWorks agent version is the latest at time of writing (4023), using Chef 12.13.37.
This is the code in the cookbook trying use the matched number:
short_app_name.to_s + node['hostname'][/([\d]+)$/, 1].to_s + '.' + app['domains'].first
The run fails with type error
no implicit conversion of nil into String. However, regex searches against that property work earlier in the recipe, when checking the node's number suffix. Is there a different method I should be using to extract the node's suffix?
app['domains'].first is populated. This line still fails with the same type error if it is swapped out with