cat /etc/ansible/hosts
[nodes]
10.2.1.232key=232
10.2.1.43 key=43
cat debug.yaml
---- name: test how to use command module
hosts: nodes
remote_user: root
gather_facts: false
vars:
- content: '20181104'
tasks:
- name: create a file
shell: "echo } >/root/}.txt"
結果:cat 10.2.1.232.txt
2.gather_facts
- name: gather_facts of each host
template: src=/root/nginx.conf dest=/root/nginx.conf
cat /root/nginx.conf
worker_processes };
\\獲取ansible的要呼叫的相關函式
遠端登陸機器執行指令碼,結果輸出到以ip命名的檔案
[dev@vm_0_11_centos ~]$ cat getresult.yaml----name: test how to use command module
hosts: qiwei
become: yes
become_user: root
gather_facts:
false
vars:
- content: '
20181104
'tasks:
-name: create a file
shell:
"sh /tmp/secure1.sh >/tmp/}.log
"
收集遠端檔案到本地目錄
----name: test how to use command module
hosts: qiwei
become: yes
become_user: root
gather_facts:
false
vars:
- content: '
20181104
'tasks:
-name: copy remote file to local
fetch:
"src=/tmp/}.log dest=/tmp/1113/
"
sudo遠端執行包括變數的命令
[dev@vm_0_11_centos tmp]$ cat toip.yaml----name:
getip imformation into ip.txt
hosts: ab-pool
gather_facts:
false
become:
true
become_user: root
tasks:
-name: echo ip imformation into $ip.txt
shell: echo } > /tmp/}.txt
ansible變數引用
在 etc ansible hosts預設檔案中定義變數 test 192.168.163.130 test vars key ansible 或者192.168.163.130 key ansible test 192.168.163.130 編寫var.yaml檔案 ansible playbo...
Ansible主機和組變數定義
把乙個組作為另乙個組的子成員 atlanta host1 host2 raleigh host2 host3 southeast children atlanta raleigh southeast vars some server foo.southeast.example.com halon s...
2 使用者定義的變數, 變數定義和引用。
使用場景 一組api根據業務流程製作成測試指令碼,想要移植到其他測試環境時,由於資料庫發生了變更,有些初始化資料也相應發生了變化,例如環境位址 請求路徑等等。博主甚至把伺服器位址和介面的部分共同請求路徑都做成了自定義變數。1 新增方式 執行緒組 右鍵 新增 配置元件 使用者定義的變數 2 作用範圍 ...