我試圖從consul kv商店檢索關鍵值時出現錯誤。ansible - consul kv列出遞歸和比較關鍵值
我們將鍵值保存在config/app-name /文件夾下。有很多鑰匙。我想用領導者從領事館中找回所有關鍵的價值觀。 但得到以下錯誤:
PLAY [Adding host to inventory] **********************************************************************************************************************************************************
TASK [Adding new host to inventory] ******************************************************************************************************************************************************
changed: [localhost]
PLAY [Testing consul kv] *****************************************************************************************************************************************************************
TASK [show the lookups] ******************************************************************************************************************************************************************
fatal: [server1]: FAILED! => {"failed": true, "msg": "{{lookup('consul_kv','config/app-name/')}}: An unhandled exception occurred while running the lookup plugin 'consul_kv'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Error locating 'config/app-name/' in kv store. Error was 500 No known Consul servers"}
PLAY RECAP *******************************************************************************************************************************************************************************
server1 : ok=0 changed=0 unreachable=0 failed=1
localhost : ok=1 changed=1 unreachable=0 failed=0
這是我想要的代碼。
---
- name: Adding host to inventory
hosts: localhost
tasks:
- name: Adding new host to inventory
add_host:
name: "{{ target }}"
- name: Testing consul kv
hosts: "{{ target }}"
vars:
kv_info: "{{lookup('consul_kv','config/app-name/')}}"
become: yes
tasks:
- name: show the lookups
debug: msg="{{ kv_info }}"
但刪除文件夾和添加文件夾運行良好。但是從consul集羣獲取關鍵值卻是拋出錯誤。請在這裏建議一些更好的方法。
- name: remove folder from the store
consul_kv:
key: 'config/app-name/'
value: 'removing'
recurse: true
state: absent
- name: add folder to the store
consul_kv:
key: 'config/app-name/'
value: 'adding'
我試過這個,但仍然是同樣的錯誤。
---
- name: Adding host to inventory
hosts: localhost
environment:
ANSIBLE_CONSUL_URL: "http://consul-1.abcaa.com"
tasks:
- name: Adding new host to inventory
add_host:
name: "{{ target }}"
- name: show the lookups
debug: kv_info= "{{lookup('consul_kv','config/app-name/')}}"
謝謝。那麼你能否建議我以理想的方式來處理這個問題? – ryan1506
使您的控制主機可以訪問consul,並使用'ANSIBLE_CONSUL_URL' env變量設置正確的URL。或者搜索Ansible自定義的consul模塊,以便檢索數據。 –
謝謝我試過這個,但仍然得到500錯誤沒有已知的領事服務器 – ryan1506