pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <bdo id='ynWFU'></bdo><ul id='ynWFU'></ul>
  • <small id='ynWFU'></small><noframes id='ynWFU'>

      <i id='ynWFU'><tr id='ynWFU'><dt id='ynWFU'><q id='ynWFU'><span id='ynWFU'><b id='ynWFU'><form id='ynWFU'><ins id='ynWFU'></ins><ul id='ynWFU'></ul><sub id='ynWFU'></sub></form><legend id='ynWFU'></legend><bdo id='ynWFU'><pre id='ynWFU'><center id='ynWFU'></center></pre></bdo></b><th id='ynWFU'></th></span></q></dt></tr></i><div class="i22oemg" id='ynWFU'><tfoot id='ynWFU'></tfoot><dl id='ynWFU'><fieldset id='ynWFU'></fieldset></dl></div>
      <tfoot id='ynWFU'></tfoot>
    1. <legend id='ynWFU'><style id='ynWFU'><dir id='ynWFU'><q id='ynWFU'></q></dir></style></legend>
      1. 如何在ansible中為不同的主機使用另一個任務中的

        How to use return values of one task in another task for a different host in ansible(如何在ansible中為不同的主機使用另一個任務中的一個任務的返回值)

                • <bdo id='TSIe3'></bdo><ul id='TSIe3'></ul>

                  <small id='TSIe3'></small><noframes id='TSIe3'>

                  <i id='TSIe3'><tr id='TSIe3'><dt id='TSIe3'><q id='TSIe3'><span id='TSIe3'><b id='TSIe3'><form id='TSIe3'><ins id='TSIe3'></ins><ul id='TSIe3'></ul><sub id='TSIe3'></sub></form><legend id='TSIe3'></legend><bdo id='TSIe3'><pre id='TSIe3'><center id='TSIe3'></center></pre></bdo></b><th id='TSIe3'></th></span></q></dt></tr></i><div class="qqgye0s" id='TSIe3'><tfoot id='TSIe3'></tfoot><dl id='TSIe3'><fieldset id='TSIe3'></fieldset></dl></div>
                  <legend id='TSIe3'><style id='TSIe3'><dir id='TSIe3'><q id='TSIe3'></q></dir></style></legend>

                  <tfoot id='TSIe3'></tfoot>

                    <tbody id='TSIe3'></tbody>
                  本文介紹了如何在ansible中為不同的主機使用另一個任務中的一個任務的返回值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我試圖為由 2 個 mysql 主機組成的主機組使用 ansible 設置 mysql 主從復制.

                  I was trying to setup mysql master slave replication with ansible for a hostgroup consisting of 2 mysql hosts.

                  這是我的場景:

                  我在第一個主機上運行一個任務并跳過第二個主機,所以第一個任務(即主復制狀態)返回一些值,如位置、文件等.

                  I run one task in the 1st host and skips the 2nd host, so the 1st task (i.e master replication status) returns some values like Position, File etc.

                  然后,我在第 2 個主機上運行另一個任務(跳過第一個主機),該任務使用第一個任務的返回值,如 master.Position、master.File 等.

                  Then, I run another task in 2nd host (skips the 1st hosts), This task uses the return values of the 1st task like master.Position, master.File etc.

                  現在,當我運行劇本時,第一個任務的變量似乎在第二個任務中不起作用

                  Now, when I run the playbook, the variables of the 1st task does not seem to be working in the 2nd task

                  庫存文件

                      [mysql]
                      stagmysql01 ansible_host=1.1.1.1 ansible_ssh_user=ansible ansible_connection=ssh
                      stagmysql02 ansible_host=1.1.1.2 ansible_ssh_user=ansible ansible_connection=ssh 
                  

                  Master 上的任務

                  - name: Mysql - Check master replication status.
                    mysql_replication: mode=getmaster
                    register: master
                  
                  - debug: var=master
                  

                  Slave 上的任務

                  - name: Mysql - Configure replication on the slave.
                    mysql_replication:
                      mode: changemaster
                      master_host: "{{ replication_master }}"
                      master_user: "{{ replication_user }}"
                      master_password: "{{ replication_pass }}"
                      master_log_file: "{{ master.File }}"
                      master_log_pos: "{{ master.Position }}"
                    ignore_errors: True
                  

                  主輸出

                  TASK [Mysql_Base : Mysql - Check master replication status.] ****************
                  skipping: [stagmysql02]
                  ok: [stagmysql01]
                  
                  TASK [Mysql_Base : debug] ***************************************************
                  ok: [stagmysql01] => {
                      "master": {
                          "Binlog_Do_DB": "", 
                          "Binlog_Ignore_DB": "mysql,performance_schema", 
                          "Executed_Gtid_Set": "", 
                          "File": "mysql-bin.000003", 
                          "Is_Master": true, 
                          "Position": 64687163, 
                          "changed": false, 
                          "failed": false
                      }
                  }
                  ok: [stagmysql02] => {
                      "master": {
                          "changed": false, 
                          "skip_reason": "Conditional result was False", 
                          "skipped": true
                      }
                  }
                  

                  從輸出

                  TASK [Mysql_Base : Mysql - Configure replication on the slave.] *************
                  skipping: [stagmysql01]
                  fatal: [stagmysql02]: FAILED! => {"failed": true, "msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'File'\n\nThe error appears to have been in '/root/ansible/roles/Mysql_Base/tasks/replication.yml': line 30, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Mysql - Configure replication on the slave.\n  ^ here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'dict object' has no attribute 'File'"}
                  ...ignoring
                  

                  正如您在上面看到的,由于未定義的變量,第二個主機的第二個任務失敗.但是,第一個主機的第一個任務中存在所需的變量.

                  As, you can see above, the 2nd task failed for 2nd host because of undefined variables. However the required variables are there in 1st task of 1st host.

                  如何在另一個任務中使用從第一臺主機返回到第二臺主機的變量?

                  How do I use the variables returned from 1st host in 2nd host in another task ?

                  P.S:我見過使用 {{ hostvars['inventory_hostname']['variable'] }} 的方法.但是我對這種方法很困惑,因為需要直接添加庫存主機名或 IP 地址.我正在尋找可用于不同清單文件和劇本的通用模板.

                  P.S: I have seen the approach of using {{ hostvars['inventory_hostname']['variable'] }}. However I'm quite confused with this approach as the inventory_hostname or IP address needs to be added directly. I was looking for a common template that can be used for different inventory files and playbooks.

                  推薦答案

                  我解決了我的問題>hostvars.

                  I was able to solve my problem by defining the variables to a new dummy host and then using it across the playbook with hostvars.

                  如何設置注冊變量以在 ansible 中的播放之間保持不變?但是直到我發布這個問題我才注意到它.

                  Similar solution was already mentioned in one of the answers in How do I set register a variable to persist between plays in ansible? However I did not notice it until I posted this question.

                  這是我在 ansible 任務中所做的:

                  Here is what I did in the ansible tasks:

                  • 我創建了一個虛擬主機 master_value_holder 并定義了所需的變量.(這里我需要 master_log_filemaster_log_Postion)
                  • 使用 hostvars['master_value_holder']['master_log_file'] 訪問變量
                  • I have created a dummy host master_value_holder and defined the required variables. (Here I needed master_log_file and master_log_Postion)
                  • Accessed the variables using hostvars['master_value_holder']['master_log_file']

                  Master 上的任務

                  - name: Mysql - Check master replication status.
                    mysql_replication: mode=getmaster
                    register: master
                  
                  - name: "Add master return values to a dummy host"
                    add_host:
                      name:   "master_value_holder"
                      master_log_file: "{{ master.File }}"
                      master_log_pos: "{{ master.Position }}"
                  

                  Slave 的任務

                  - name: Mysql - Displaying master replication status
                    debug: msg="Master Bin Log File  is {{ hostvars['master_value_holder']['master_log_file'] }} and Master Bin Log Position is {{ hostvars['master_value_holder']['master_log_pos'] }}"
                  
                  - name: Mysql - Configure replication on the slave.
                    mysql_replication:
                      mode: changemaster
                      master_host: "{{ replication_master }}"
                      master_user: "{{ replication_user }}"
                      master_password: "{{ replication_pass }}"
                      master_log_file: "{{ hostvars['master_value_holder']['master_log_file'] }}"
                      master_log_pos: "{{ hostvars['master_value_holder']['master_log_pos'] }}"
                    when: ansible_eth0.ipv4.address != replication_master and not slave.Slave_SQL_Running
                  

                  輸出

                  TASK [Mysql_Base : Mysql - Check master replication status.] ****************
                  skipping: [stagmysql02]
                  ok: [stagmysql01]
                  
                  TASK [AZ-Mysql_Base : Add master return values to a dummy host] ****************
                  changed: [stagmysql01]
                  
                  TASK [AZ-Mysql_Base : Mysql - Displaying master replication status] ************
                  ok: [stagmysql01] => {
                      "msg": "Master Bin Log File  is mysql-bin.000001 and Master Bin Log Position is 154"
                  }
                  ok: [stagmysql02] => {
                      "msg": "Master Bin Log File  is mysql-bin.000001 and Master Bin Log Position is 154"
                  }
                  
                  TASK [AZ-Mysql_Base : Mysql - Configure replication on the slave.] *************
                  skipping: [stagmysql01]
                  skipping: [stagmysql02]
                  

                  從上面的輸出中可以看出,主復制狀態現在對兩臺主機都可用.

                  As you can see from the above output that the master replication status is available for both the hosts now.

                  這篇關于如何在ansible中為不同的主機使用另一個任務中的一個任務的返回值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  SQL query to get all products, categories and meta data woocommerce/wordpress(獲取所有產品、類別和元數據的 SQL 查詢 woocommerce/wordpress)
                  How to use MySQL in WSL (Windows Subsystem for Linux)?(如何在 WSL(Linux 的 Windows 子系統)中使用 MySQL?)
                  PowerShell MySQL Backup Script Error in Task Scheduler 0x00041301(任務計劃程序中的 PowerShell MySQL 備份腳本錯誤 0x00041301)
                  Import the data from the XML files into a MySQL database(將數據從 XML 文件導入 MySQL 數據庫)
                  installed Xampp on Windows 7 32-bit. Errors when starting(在 Windows 7 32 位上安裝 Xampp.啟動時的錯誤)
                  Mysql lower case table on Windows xampp(Windows xampp 上的 Mysql 小寫表)
                  <i id='IYc3q'><tr id='IYc3q'><dt id='IYc3q'><q id='IYc3q'><span id='IYc3q'><b id='IYc3q'><form id='IYc3q'><ins id='IYc3q'></ins><ul id='IYc3q'></ul><sub id='IYc3q'></sub></form><legend id='IYc3q'></legend><bdo id='IYc3q'><pre id='IYc3q'><center id='IYc3q'></center></pre></bdo></b><th id='IYc3q'></th></span></q></dt></tr></i><div class="o22iy2e" id='IYc3q'><tfoot id='IYc3q'></tfoot><dl id='IYc3q'><fieldset id='IYc3q'></fieldset></dl></div>
                    <tbody id='IYc3q'></tbody>

                      <legend id='IYc3q'><style id='IYc3q'><dir id='IYc3q'><q id='IYc3q'></q></dir></style></legend>
                        <bdo id='IYc3q'></bdo><ul id='IYc3q'></ul>
                          • <tfoot id='IYc3q'></tfoot>

                            <small id='IYc3q'></small><noframes id='IYc3q'>

                          • 主站蜘蛛池模板: 点胶机_点胶阀_自动点胶机_智能点胶机_喷胶机_点胶机厂家【欧力克斯】 | 蜗轮丝杆升降机-螺旋升降机-丝杠升降机厂家-润驰传动 | 苏州工作服定做-工作服定制-工作服厂家网站-尺品服饰科技(苏州)有限公司 | 德州网站开发定制-小程序开发制作-APP软件开发-「两山开发」 | 防爆正压柜厂家_防爆配电箱_防爆控制箱_防爆空调_-盛通防爆 | 成都中天自动化控制技术有限公司| 金联宇电缆|广东金联宇电缆厂家_广东金联宇电缆实业有限公司 | 六自由度平台_六自由度运动平台_三自由度摇摆台—南京全控科技 | 西门子代理商_西门子变频器总代理-翰粤百科 | 美能达分光测色仪_爱色丽分光测色仪-苏州方特电子科技有限公司 | 泰来华顿液氮罐,美国MVE液氮罐,自增压液氮罐,定制液氮生物容器,进口杜瓦瓶-上海京灿精密机械有限公司 | 「安徽双凯」自动售货机-无人售货机-成人用品-自动饮料食品零食售货机 | 英思科GTD-3000EX(美国英思科气体检测仪MX4MX6)百科-北京嘉华众信科技有限公司 | 建大仁科-温湿度变送器|温湿度传感器|温湿度记录仪_厂家_价格-山东仁科 | 彩信群发_群发彩信软件_视频短信营销平台-达信通 | 【MBA备考网】-2024年工商管理硕士MBA院校/报考条件/培训/考试科目/提前面试/考试/学费-MBA备考网 | 报警器_家用防盗报警器_烟雾报警器_燃气报警器_防盗报警系统厂家-深圳市刻锐智能科技有限公司 | 万家财经_财经新闻_在线财经资讯网 | 成都顶呱呱信息技术有限公司-贷款_个人贷款_银行贷款在线申请 - 成都贷款公司 | 苏州西装定制-西服定制厂家-职业装定制厂家-尺品服饰西装定做公司 | 工业雾炮机_超细雾炮_远程抑尘射雾器-世纪润德环保设备 | 展厅设计公司,展厅公司,展厅设计,展厅施工,展厅装修,企业展厅,展馆设计公司-深圳广州展厅设计公司 | 电机修理_二手电机专家-河北豫通机电设备有限公司(原石家庄冀华高压电机维修中心) | 沈飞防静电地板__机房地板-深圳市沈飞防静电设备有限公司 | 上海盐水喷雾试验机_两厢式冷热冲击试验箱-巨怡环试 | 立式硫化罐-劳保用品硫化罐-厂家直销-山东鑫泰鑫硫化罐厂家 | 兰州牛肉面加盟,兰州牛肉拉面加盟-京穆兰牛肉面 | 对照品_中药对照品_标准品_对照药材_「格利普」高纯中药标准品厂家-成都格利普生物科技有限公司 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 组织研磨机-高通量组织研磨仪-实验室多样品组织研磨机-东方天净 传递窗_超净|洁净工作台_高效过滤器-传递窗厂家广州梓净公司 | 铝合金电阻-无源谐波滤波器-上海稳达电讯设备厂 | 沟盖板_复合沟盖板厂_电力盖板_树脂雨水篦子-淄博拜斯特 | 代办建筑资质升级-建筑资质延期就找上海国信启航 | 开云(中国)Kaiyun·官方网站-登录入口 | 水质监测站_水质在线分析仪_水质自动监测系统_多参数水质在线监测仪_水质传感器-山东万象环境科技有限公司 | 储气罐,真空罐,缓冲罐,隔膜气压罐厂家批发价格,空压机储气罐规格型号-上海申容压力容器集团有限公司 | 磁力抛光机_磁力研磨机_磁力去毛刺机_精密五金零件抛光设备厂家-冠古科技 | 合肥防火门窗/隔断_合肥防火卷帘门厂家_安徽耐火窗_良万消防设备有限公司 | 滚塑PE壳体-PE塑料浮球-警示PE浮筒-宁波君益塑业有限公司 | Duoguan 夺冠集团 | 禹城彩钢厂_钢结构板房_彩钢复合板-禹城泰瑞彩钢复合板加工厂 | 切铝机-数控切割机-型材切割机-铝型材切割机-【昆山邓氏精密机械有限公司】 |