Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

structured input to hash #3

Closed
ogaida opened this issue Feb 16, 2020 · 3 comments
Closed

structured input to hash #3

ogaida opened this issue Feb 16, 2020 · 3 comments

Comments

@ogaida
Copy link
Contributor

ogaida commented Feb 16, 2020

good morning to japan,

this is a kind of feature request. If you like, i could make a pull request, please tell me.

when i try to use an attribute of the the type hash in my module and the hash data are coming from a play, i always get a kind of a json string.

for example:

if i use:

class Demo < AnsibleModule
  attribute :data, Hash

with a play like this:

  - name: structured data test
    demo:
      data:
        users:
          gaida:
            alias: Oliver Gaida
            password: myStrongPassword

if i check later the class-type of @data it is always a string, but a hash is expected.

To change this behavior, i have changed the params function in the ansible_module libary to this:

    def params
      return @params if @params
      @params = ActiveSupport::HashWithIndifferentAccess.new
      File.open(ARGV[0]) do |fh|
        @params.update JSON.parse(fh.read())
      end
    end

but than they module has to tell ansible, that it needs the modules parameters in json format. see https://docs.ansible.com/ansible/latest/dev_guide/developing_program_flow_modules.html#non-native-want-json-modules
for this to work you have to put # WANT_JSON anywhere in the model-file:

#!/usr/bin/ruby

require 'ansible_module'
# WANT_JSON

class Demo < AnsibleModule

as a side-affect, there is no need for the shellwords module anymore.

kind regards
Oliver

@kuroda
Copy link
Owner

kuroda commented Feb 21, 2020

@ogaida

Sorry for late reply!

Please make your PR.

@ogaida
Copy link
Contributor Author

ogaida commented Feb 26, 2020

Have you seen my pr?

@ogaida
Copy link
Contributor Author

ogaida commented May 15, 2020

It would be really great, if you could do the merge . Thx

@kuroda kuroda closed this as completed May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants