Method: QB::Ansible::Module.load_args_from_JSON_file

Defined in:
lib/qb/ansible/module.rb

.load_args_from_JSON_file(file_path) ⇒ Array<(Hash, Hash?)>

Load args from a file in JSON format.

Parameters:

  • file_path (String | Pathname)

    File path to load from.

Returns:

  • (Array<(Hash, Hash?)>)

    Tuple of:

    1. args:
      • Hash<String, *>
    2. args_source:
      • nil | Hash{ type: :file, path: String, contents: String }


220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/qb/ansible/module.rb', line 220

def self.load_args_from_JSON_file file_path
  file_contents = File.read file_path

  args = JSON.load( file_contents ).with_indifferent_access

  t.hash_( keys: t.str ).check( args ) do |type:, value:|
    binding.erb <<~END
      JSON file contents must load into a `Hash<String, *>`
      
      Loaded value (of class <%= value.class %>):
      
          <%= value.pretty_inspect %>
      
    END
  end
  
  [ args, { type: :file,
            path: file_path.to_s,
            contents: file_contents,
          } ]
end