Ansible:カールコマンドが失敗しました。

Ansible:カールコマンドが失敗しました。

私は時間の経過とともに成長する小さなプレイブックを書きました。

まず、「https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.65/bin/」にアクセスできる削除サーバーにスクリプトを作成し、スクリプトファイルの内容をダウンロードしました。 ~である

#!/bin/bash -x
version="9.0.65"
filename="apache-tomcat-"$version".tar.gz"
cd /root/ApacheTomcat/files
curl -fk https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.65/bin/apache-tomcat-"$version".tar.gz -o $filename
if [[ -e /root/ApacheTomcat/files/$filename ]]
        then
                echo -e "\nApache Tomcat $version downloaded under $PWD on `hostname -i`"
else
        echo -e "\nProblem occured please check it"
fi

その後、Ansibleコントローラに小さなスクリプトを書きましたが、内容は次のとおりです。

---                                                         
- name: Download Latest version of Apache Tomcat            
  hosts: 172.16.8.50                                        
  tasks:                                                    
    - name: Downloading Apache on Central Repository Server 
      command: sh /root/ApacheTomcat/apachetomcat.sh        
      register: _check_download_apache_status               
    - name:                                                 
      debug:                                                
        var: _check_download_apache_status                  
...                        

        

サーバーでシェルスクリプトを実行すると動作し、ファイルをダウンロードしますが、ansible Playbookを介して実行すると「ホストを確認できません:dlcdn.apache.org;不明なエラー」エラーが発生します。

ansible-playbook apache-update.yaml -b

PLAY [Download Latest version of Apache Tomcat] *********************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [172.16.8.50]

TASK [Downloading Apache on Central Repository Server] **************************************************************************************************************************************************************************************
changed: [172.16.8.50]

TASK [debug] ********************************************************************************************************************************************************************************************************************************
ok: [172.16.8.50] => {
    "_check_download_apache_status": {
        "changed": true,
        "cmd": [
            "sh",
            "/root/ApacheTomcat/apachetomcat.sh"
        ],
        "delta": "0:00:00.016762",
        "end": "2022-08-15 11:35:11.229642",
        "failed": false,
        "rc": 0,
        "start": "2022-08-15 11:35:11.212880",
        "stderr": "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- -
-:--:-- --:--:--     0curl: (6) Could not resolve host: dlcdn.apache.org; Unknown error",
        "stderr_lines": [
            "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current",
            "                                 Dload  Upload   Total   Spent    Left  Speed",
            "",
            "  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: dlcdn.apache.org; Unknown error"
        ],
        "stdout": "\nProblem occured please check it",
        "stdout_lines": [
            "",
            "Problem occured please check it"
        ]
    }
}

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
172.16.8.50                : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

ベストアンサー1

~について

私は時間の経過とともに成長する小さなプレイブックを書きました。

与えられたコメントに応じて、次の例で簡単に始めることができます。

---
- hosts: central_repository_server # or your remote hosts
  become: false
  gather_facts: false
  
  vars:
  
    VERSION: "9.0.65"

  tasks:
  
  - name: Download latest version of Apache Tomcat
    get_url:
      url: "https://dlcdn.apache.org/tomcat/tomcat-9/v{{ VERSION }}/bin/apache-tomcat-{{ VERSION }}.tar.gz"
      dest: "/home/{{ ansible_user }}"
    register: result
    environment:
      http_proxy: "localhost:3128"
      https_proxy: "localhost:3128"

以前は完全に機能し、テストされたソリューションを提供していませんでしたが、問題を解決するためのアイデアと方法のみを提供していたので、ここで実際の例を見つけてください。

---
- hosts: localhost
  become: false
  gather_facts: false

  vars:

    VERSION: "9.0.65"

  tasks:

  - name: Get file using 'uri' module
    uri:
      url: "https://dlcdn.apache.org/tomcat/tomcat-9/v{{ VERSION }}/bin/apache-tomcat-{{ VERSION }}.tar.gz"
      dest: "/home/{{ ansible_user }}"
      method: GET
      status_code: 200,304
      creates: "apache-tomcat-{{ VERSION }}.tar.gz"
    environment:
      http_proxy: "localhost:3128"
      https_proxy: "localhost:3128"

追加文書

各モジュールのドキュメントを読み、特定のプロパティとさまざまな動作に慣れることをお勧めします。

おすすめ記事