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

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

    • <bdo id='1EmZk'></bdo><ul id='1EmZk'></ul>

    1. <tfoot id='1EmZk'></tfoot>

        <small id='1EmZk'></small><noframes id='1EmZk'>

        如何在ansible中為不同的主機使用另一個任務中的

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

        1. <i id='JQlqX'><tr id='JQlqX'><dt id='JQlqX'><q id='JQlqX'><span id='JQlqX'><b id='JQlqX'><form id='JQlqX'><ins id='JQlqX'></ins><ul id='JQlqX'></ul><sub id='JQlqX'></sub></form><legend id='JQlqX'></legend><bdo id='JQlqX'><pre id='JQlqX'><center id='JQlqX'></center></pre></bdo></b><th id='JQlqX'></th></span></q></dt></tr></i><div class="xrnbhj7" id='JQlqX'><tfoot id='JQlqX'></tfoot><dl id='JQlqX'><fieldset id='JQlqX'></fieldset></dl></div>

          <tfoot id='JQlqX'></tfoot>

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

            <tbody id='JQlqX'></tbody>
              • <bdo id='JQlqX'></bdo><ul id='JQlqX'></ul>

                  <legend id='JQlqX'><style id='JQlqX'><dir id='JQlqX'><q id='JQlqX'></q></dir></style></legend>
                  本文介紹了如何在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 小寫表)

                    <tbody id='zPONz'></tbody>

                      <legend id='zPONz'><style id='zPONz'><dir id='zPONz'><q id='zPONz'></q></dir></style></legend>

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

                        <tfoot id='zPONz'></tfoot>
                        • <bdo id='zPONz'></bdo><ul id='zPONz'></ul>

                            <i id='zPONz'><tr id='zPONz'><dt id='zPONz'><q id='zPONz'><span id='zPONz'><b id='zPONz'><form id='zPONz'><ins id='zPONz'></ins><ul id='zPONz'></ul><sub id='zPONz'></sub></form><legend id='zPONz'></legend><bdo id='zPONz'><pre id='zPONz'><center id='zPONz'></center></pre></bdo></b><th id='zPONz'></th></span></q></dt></tr></i><div class="xjx77tl" id='zPONz'><tfoot id='zPONz'></tfoot><dl id='zPONz'><fieldset id='zPONz'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: 威客电竞(vk·game)·电子竞技赛事官网 | 西门子气候补偿器,锅炉气候补偿器-陕西沃信机电工程有限公司 | 贝朗斯动力商城(BRCPOWER.COM) - 买叉车蓄电池上贝朗斯商城,价格更超值,品质有保障! | 阳光1号桔柚_无核沃柑_柑橘新品种枝条苗木批发 - 苧金网 | 海峰资讯 - 专注装饰公司营销型网站建设和网络营销培训 | 长江船运_国内海运_内贸船运_大件海运|运输_船舶运输价格_钢材船运_内河运输_风电甲板船_游艇运输_航运货代电话_上海交航船运 | 柴油机_柴油发电机_厂家_品牌-江苏卡得城仕发动机有限公司 | 杰福伦_磁致伸缩位移传感器_线性位移传感器-意大利GEFRAN杰福伦-河南赉威液压科技有限公司 | 旅游规划_旅游策划_乡村旅游规划_景区规划设计_旅游规划设计公司-北京绿道联合旅游规划设计有限公司 | MVR蒸发器厂家-多效蒸发器-工业废水蒸发器厂家-康景辉集团官网 | 上海logo设计 | 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 浙江皓格药业有限公司| 艺术涂料|木纹漆施工|稻草漆厂家|马来漆|石桦奴|水泥漆|选加河南天工涂料 | 焊缝跟踪系统_激光位移传感器_激光焊缝跟踪传感器-创想智控 | 全自动贴标机-套标机-工业热风机-不干胶贴标机-上海厚冉机械 | 安徽泰科检测科技有限公司【官方网站】| 数控走心机-走心机价格-双主轴走心机-宝宇百科 | 乐之康护 - 专业护工服务平台,提供医院陪护-居家照护-居家康复 | 换网器_自动换网器_液压换网器--郑州海科熔体泵有限公司 | 安平县鑫川金属丝网制品有限公司,防风抑尘网,单峰防风抑尘,不锈钢防风抑尘网,铝板防风抑尘网,镀铝锌防风抑尘网 | 奶茶加盟,奶茶加盟店连锁品牌-甜啦啦官网 | 锻造液压机,粉末冶金,拉伸,坩埚成型液压机定制生产厂家-山东威力重工官方网站 | KBX-220倾斜开关|KBW-220P/L跑偏开关|拉绳开关|DHJY-I隔爆打滑开关|溜槽堵塞开关|欠速开关|声光报警器-山东卓信有限公司 | 中高频感应加热设备|高频淬火设备|超音频感应加热电源|不锈钢管光亮退火机|真空管烤消设备 - 郑州蓝硕工业炉设备有限公司 | 电磁辐射仪-电磁辐射检测仪-pm2.5检测仪-多功能射线检测仪-上海何亦仪器仪表有限公司 | 智能气瓶柜(大型气瓶储存柜)百科| 【同风运车官网】一站式汽车托运服务平台,验车满意再付款 | 面粉仓_储酒罐_不锈钢储酒罐厂家-泰安鑫佳机械制造有限公司 | 高精度-恒温冷水机-螺杆式冰水机-蒸发冷冷水机-北京蓝海神骏科技有限公司 | 精密模具加工制造 - 富东懿| 河南卓美创业科技有限公司-河南卓美防雷公司-防雷接地-防雷工程-重庆避雷针-避雷器-防雷检测-避雷带-避雷针-避雷塔、机房防雷、古建筑防雷等-山西防雷公司 | 实木家具_实木家具定制_全屋定制_美式家具_圣蒂斯堡官网 | 德国UST优斯特氢气检漏仪-德国舒赐乙烷检测仪-北京泽钏 | 宿舍管理系统_智慧园区系统_房屋/房产管理系统_公寓管理系统 | 废气处理设备-工业除尘器-RTO-RCO-蓄热式焚烧炉厂家-江苏天达环保设备有限公司 | 单螺旋速冻机-双螺旋-流态化-隧道式-食品速冻机厂家-广州冰泉制冷 | 厌氧反应器,IC厌氧反应器,厌氧三相分离器-山东创博环保科技有限公司 | 高光谱相机-近红外高光谱相机厂家-高光谱成像仪-SINESPEC 赛斯拜克 | 深圳活动策划公司|庆典策划|专业公关活动策划|深圳艺典文化传媒 重庆中专|职高|技校招生-重庆中专招生网 | 不锈钢复合板厂家_钛钢复合板批发_铜铝复合板供应-威海泓方金属复合材料股份有限公司 |