我一直在嘗試從Ansible URI模塊中執行curl命令,但是沒有成功。誰能幫助我理解我的錯誤呢?
CURL命令是:
curl -X POST -H "Content-Type: text/plain" -H "X-Vuls-OS-Family: `lsb_release -si | awk '{print tolower(1)}'`" -H "X-Vuls-OS-Release: `lsb_release -sr | awk '{print $1}'`" -H "X-Vuls-Kernel-Release: `uname -r`" -H "X-Vuls-Server-Name: `hostname`" --data-binary "$(dpkg-query -W -f="${binary:Package},${db:Status-Abbrev},${Version},${source},${source:Version}")
")" https://abc.xyz.co/vuls > /path/to/report.json**。
關于逗號
我現在使用的playbook是:
- hosts: localhost
ignore_errors: yes
成為:是
任務。
- name: 運行Vuls掃描
uri:
方法。POST
url: https://abc.xyz.co/vuls
headers:
Content-Type: text/plain
X-Vuls-OS-Family: lsb_release -si | awk '{print tolower(1)}' 。
X-Vuls-OS-Release:lsb_release -sr | awk '{print $1}'
X-Vuls-Kernel-Release: uname -r
X-Vuls-Server-Name: hostname
創建。/home/aman/vuls-report.json
我知道這個playbook還沒有完成,因為我無法管理playbook中的部分命令(**--data-binary "$(dpkg-query -W -f="${binary:Package},${db:Status-Abbrev},${Version},${Source},${source:Version}
")"**)。) 對此我很抱歉,但我不知道如何在playbook中管理它。誰能幫助我解決這個問題。
謝謝你
PS:我在StackOverflow上看到了一些關于這個ansible URI模塊和curl方法的現有問題,但它沒有幫助我。
uj5u.com熱心網友回復:
你不能在Ansible模塊內運行任意的Shell命令。然而,由于你正在收集關于主機的事實,你可以利用這些。試著這樣做:
- hosts: localhost
ignore_errors: yes
成為:是
任務。
- name: 運行Vuls掃描
uri:
方法。POST
url: https://abc.xyz.co/vuls
headers:
Content-Type: text/plain
X-Vuls-OS-Family: "{{ ansible_distribution }}"
X-Vuls-OS-Release: "{{ ansible_distribution_version}}"
X-Vuls-Kernel-Release。"{{ ansible_kernel }}"
X-Vuls-Server-Name: "{{ inventory_hostname }}"
創建。/home/aman/vuls-report.json
對于更復雜的資訊,比如你的dpkg查詢,你可以做一些類似于
- name: dpkg query
shell: "dpkg-query -W -f='${binary:Package},${db:Status-Abbrev},${Version},${Source},${source:Version}'
'"
注冊:query_results
- 名稱:檢查變數內容
debug:
var: query_results
免責宣告:這是未經測驗的,但你應該明白這個道理。
uj5u.com熱心網友回復:
我沒有使用URI模塊或作為一個shell命令來運行這個命令,而是作為一個shell腳本運行它。我在.sh檔案中粘貼了同樣的命令,并在下面的playbook中傳遞它。
- hosts: localhost
ignore_errors: yes
成為:是
任務。
- name: 運行Vuls掃描
成為:是
shell: ansible.sh
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/319769.html
標籤:
上一篇:Nginx安裝與反向代理負載均衡
