在consul_kv ansible模块中加载键值对

时间:2017-03-30 10:09:37

标签: ansible consul

我们在json格式的文件中有键值对。

from tkinter import *

class Window:
    def __init__(self, root,a):
        self.root = root
        action = self.find_command(a)

        for y,element in enumerate(action):
            self.Make_Button(1,y, element[0], element[1])



    def find_command(self, list_):
        d = {"test": self.printX, "value" : self.printY, "practice" : self.printZ}
        action = []
        for element in list_:
            for key, value in d.items():
                if key == element:
                    action.append([key, value])
        return(action)


    def Make_Button(self, x, y, text_, command_):
        self.StopButton = Button(self.root, text = text_, command =  command_)
        self.StopButton.grid(row = x, column = y, columnspan = 1, pady=(2,1))

    def printX(self):
        print("testX")

    def printY(self):
        print("testY")

    def printZ(self):
        print("testZ")


a = ["test", "practice"]

root = Tk()
Window = Window(root,a)
Window.root.mainloop()

我想将这些值放在consul集群中。这是我正在尝试的

{
  "app1":
 [
     {"key": "key1","value": "val1"},
     {"key": "key2","value": "val2"}


 ],
  "app2":
 [
      {"key": "key1","value": "val1"},
     {"key": "key2","value": "val2"}

 ],
  "app3":
 [
     {"key": "key1","value": "val1"},
     {"key": "key2","value": "val2"}

 ]
}

1 个答案:

答案 0 :(得分:0)

当您不依赖于JSON结构时,可以使用以下格式:

myitems:
 - site:
      - {"key": "abcUrl","value": "http://prod.abc.url"}
      - {"key": "user.url","value": "http://prod.abc.login"}
      - {"key": "security.logout.url","value": "http://prod.abc.logout"}
 - site:
      - {"key": "abcUrl","value": "http://prod.abc.url"}
      - {"key": "user.url","value": "http://prod.abc.login"}
      - {"key": "security.logout.url","value": "http://prod.abc.logout"}
 - site:
      - {"key": "abcUrl","value": "http://prod.abc.url"}
      - {"key": "user.url","value": "http://prod.abc.login"}
      - {"key": "security.logout.url","value": "http://prod.abc.logout"}
 - site:
      - {"key": "abcUrl","value": "http://prod.abc.url"}
      - {"key": "user.url","value": "http://prod.abc.login"}
      - {"key": "security.logout.url","value": "http://prod.abc.logout"}

(如果您需要内部的dc [1-4],请将其写在键/级别上。)

使用此格式,您可以像这样提取键/值:

- name: remove a key from the store
  debug:
    msg: "key is {{ item.1.key }} and the value is {{ item.1.value }}"
  with_subelements:
    - "{{ myitems }}"
    - site