日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ansible-playbook相关

發布時間:2024/1/17 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ansible-playbook相关 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

獲取目標主機的信息

ansible all -m setup -a "filter=ansible_os_family"

獲取ip地址

# {{ ansible_eth0.ipv4.address }} 如: CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname={{ ansible_eth0.ipv4.address }}"

定義變量

--- - hosts: allvars:username: chentiangangpasswd: {{ ansible_eth0.ipv4.address }}

使用ip地址最后一段做my.cnf的server-id

- name: change my.cnf server-idshell: server_id=`echo {{ ansible_eth0.ipv4.address }} | awk -F "." '{print \$4}'` ; sed -i "s#server-id = 1#server-id = ${server_id}#g" /etc/my.cnf

不執行僅測試

ansible-playbook test.yml -C

安裝一個zabbix-agent

--- - hosts: newserverhandlers:- name: restart zabbix-agentservice: name=zabbix-agent state=restartedtasks:- name: install zabbix22-agentyum: name={{ item }} state=latest # -name: 刪除zabbix-agent # yum: name={{ item }} state=absentwith_items: zabbix22-agent- name: templatetemplate: src=/etc/ansible/roles/zabbix22-agent/templates/zabbix_agentd.conf dest=/etc/zabbix_agentd.conf owner=root group=root mode=0644notify: restart zabbix-agentwhen: ansible_os_family == "RedHat" and ansible_lsb.major_release == "7"- name: start zabbix-agentservice: name=zabbix-agent state=started

檢查語法

ansible-playbook main.yml --syntax-check

查看錯誤模塊

ansible-playbook main.yml --verbose

要在運行之前查看哪些主機會受到影響,請執行以下操作:

ansible-playbook playbook.yml --list-hosts

正則

jinja中的正則
這邊使用match和search關鍵字,匹配比較簡單,用來when判斷非常方便,直接貼一下官網代碼和鏈接。

vars:url: "http://example.com/users/foo/resources/bar"tasks:- debug: "msg='matched pattern 1'"when: url | match("http://example.com/users/.*/resources/.*")- debug: "msg='matched pattern 2'"when: url | search("/users/.*/resources/.*")- debug: "msg='matched pattern 3'"when: url | search("/users/")--- - hosts: tomcatserverstasks:- name: create dirshell: hostnamewhen: ansible_hostname | search("inner-api")

指定遠程連接端口

--- - hosts: ecAppBport: 22tasks:- name: pingping:

首次連接不輸yes的方法

打開/etc/ansible/ansible.cfg這一行的注釋

默認情況下,首次登陸一臺服務器,系統會提示是否要記住對端的指紋,用ansible也會這樣,這樣會導致需要手工輸入yes或no,ansible 才可以往下執行。如需避免這種情況,需要在 /etc/ansible/ansible.cfg 文件中設置 host_key_checking = False # uncomment this to disable SSH key host checking host_key_checking = False

變量注冊

--- - name: 注冊變量shell: hostname | sed -r 's#(.*)(-)([A-Z])([0-9])#\1#g'register: pkgname# 通過切片取到最終想要的結果 - debug: "msg='{{ pkgname.stdout_lines[0] }}.war'"

執行的時候不獲取主機信息(Gathering Facts)

--- - hosts: java*gather_facts: noroles:- log/log-privileges

替換

- name: PMM | Fix nginx configreplace:dest: /etc/nginx/nginx.confregexp: '^(\s*)listen'replace: '\1#listen'

ansible roles詳解

https://www.cnblogs.com/zhaojiankai/p/7655855.html

轉載于:https://www.cnblogs.com/Csir/p/8379499.html

總結

以上是生活随笔為你收集整理的ansible-playbook相关的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。