久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='6qDDh'><tr id='6qDDh'><dt id='6qDDh'><q id='6qDDh'><span id='6qDDh'><b id='6qDDh'><form id='6qDDh'><ins id='6qDDh'></ins><ul id='6qDDh'></ul><sub id='6qDDh'></sub></form><legend id='6qDDh'></legend><bdo id='6qDDh'><pre id='6qDDh'><center id='6qDDh'></center></pre></bdo></b><th id='6qDDh'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6qDDh'><tfoot id='6qDDh'></tfoot><dl id='6qDDh'><fieldset id='6qDDh'></fieldset></dl></div>

    • <bdo id='6qDDh'></bdo><ul id='6qDDh'></ul>

    <small id='6qDDh'></small><noframes id='6qDDh'>

  • <legend id='6qDDh'><style id='6qDDh'><dir id='6qDDh'><q id='6qDDh'></q></dir></style></legend>
    1. <tfoot id='6qDDh'></tfoot>
      1. 如何在ansible中為不同的主機使用另一個任務中的

        How to use return values of one task in another task for a different host in ansible(如何在ansible中為不同的主機使用另一個任務中的一個任務的返回值)
            <tbody id='qJQOI'></tbody>
          <tfoot id='qJQOI'></tfoot>
              <bdo id='qJQOI'></bdo><ul id='qJQOI'></ul>
              <legend id='qJQOI'><style id='qJQOI'><dir id='qJQOI'><q id='qJQOI'></q></dir></style></legend>

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

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

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

                  問題描述

                  我試圖為由 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模板網!

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

                  相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)

                    <tfoot id='CxGFm'></tfoot>
                      <tbody id='CxGFm'></tbody>

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

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

                        • <bdo id='CxGFm'></bdo><ul id='CxGFm'></ul>
                            主站蜘蛛池模板: 亚洲在线看| 亚洲综合大片69999 | 免费久| 九色.com| 婷婷成人在线 | 精品一区二区久久久久久久网精 | 日韩图区 | 一区二区三区视频在线观看 | 欧美一级在线免费 | 综合九九 | 天天操天天射综合网 | 国产精品日本一区二区在线播放 | 午夜在线视频一区二区三区 | 国产成人网 | 欧美亚洲另类丝袜综合网动图 | av永久免费 | 九九热这里只有精品在线观看 | 国产精品久久久久一区二区三区 | 日韩在线中文字幕 | 久久久久久久久久久久91 | 懂色中文一区二区在线播放 | 毛片链接 | 欧美aaaa视频 | 99热播精品 | 亚洲成人免费视频 | 密色视频 | 欧美一区二区在线观看 | 欧美激情精品久久久久 | 精品日韩在线 | 91成人免费看 | 欧美日韩在线观看一区 | 伊人网站 | 欧美国产日韩一区 | 日韩欧美手机在线 | 精品久久精品 | 欧美激情视频一区二区三区在线播放 | 在线观看av免费 | 国产不卡在线播放 | 欧美不卡一区二区三区 | 免费激情 | 国产精品美女久久久 |