-2

I'm using the mongodb3 cookbook (took from chef supermarket) in my environment. When ever we pass input for mongos template like [10.10.0.10,127.0.0.1] , the output file is created with improper syntax:

PFB out put - 

net:
port: 27017
bindIp: ! '[10.10.0.10,127.0.0.1]'

There's a ! and '' around the square brackets instead of only [10.10.0.10,127.0.0.1]

I am using below function to convert.

module Mongodb3Helper
  def mongodb_config(config)
    config.to_hash.compact.to_yaml
  end
end

class Hash
  def compact
    inject({}) do |new_hash, (k, v)|
      if v.is_a?(Hash)
        v = v.compact
        new_hash[k] = v unless v.empty?
      else
        new_hash[k] = v unless v.nil?
      end
      new_hash
    end
  end
end
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • Show your chef recipe, but there's something wrong with what you're doing here. Quoting mongo documetnation: "To bind to multiple IP addresses, enter a list of comma separated values." So just set the attribute to a string with IPs separated by a comma instead of an array and you'll be good. – Tensibai Jan 09 '17 at 09:55
  • i am passing input like this '[10.10.10.10'+',127.0.0.1]' is this correct ? – Bhupal Reddy Jan 09 '17 at 10:06
  • No, Just pass `"10.10.0.10,127.0.0.1"` a simple string with IP separated by coma... – Tensibai Jan 09 '17 at 10:08
  • ok... but i need out put like this [10.10.10.10,127.0.0.1] without quotes – Bhupal Reddy Jan 09 '17 at 10:12
  • Why would you need square brackets around ? That's not what the mongodb 3.4 documentation say. But if you really want, just add them into the string and not outside: `"[10.10.0.10,127.0.0.1]"` – Tensibai Jan 09 '17 at 10:14
  • If we want to access mongodb from remote server, in the bindip we have to mention the ip's in the square brackets, however if I pass the input "[10.10.0.10,127.0.0.1]" like this, I am getting the output as !'[10.10.0.10,127.0.0.1]' in mongos.conf – Bhupal Reddy Jan 09 '17 at 10:53
  • I'll quit here if you can't tell why 1) you need this format (and not simply 0.0.0.0 to bind to all interfaces (or just he 10.10.10.10 and not using localhost elsewhere). 2) Why you need those brackets, as far as I can read the documentation of mongodb, there's no reason.. [edit] your question (link just under) if you have informations to add. (and telling why what I said above doesn't work) – Tensibai Jan 09 '17 at 10:55
  • i want to access my mongo db agent locally and remotely, so i have mention multiple Ip's in mongos conf, previously i used to mention ip's like this "10.10.10.10,127.0.0.1" but suddenly after upgrading my mongo i am unable to access my agent remotely, so when i checked online they said i need to mention multiple ip's like this [10.10.10.10,127.0.0.1] i have made this changes manually and test, and i am able to access remotely after doing this. same changes if i pass from chef recipe it is taking extra characters - – Bhupal Reddy Jan 09 '17 at 11:20
  • Or just 0.0.0.0 to bind to all interfaces, try the things people tell to you... – Tensibai Jan 09 '17 at 11:22
  • PFB link http://stackoverflow.com/questions/17588876/mongodb-conf-bind-ip-127-0-0-1-does-not-work-but-0-0-0-0-works. i can mention 0.0.0.0 bcz it is open for all and alert logic tool is treating as vulnerabilitie – Bhupal Reddy Jan 09 '17 at 11:25
  • You are misunderstanding listening address and security groups. 0.0.0.0 means listen on all interfaces, that is 127.0.0.1 (loopback) and 10.10.10.10, your eth0 address at the same time, public IP in EC2 are Nat, you don't have a public IP directly on your instance as far as I know. – Tensibai Jan 09 '17 at 11:29

1 Answers1

0

Your code, while horribly unmaintainable due to making changes to global objects, is fine. As pointed out several times in the comments, the problem is with the data you are feeding in to that code.

coderanger
  • 52,400
  • 4
  • 52
  • 75