2017-10-04 228 views
0

我正在運行jenkins服務器10.251.130.45:8080。 服務器位於代理之後。Ansible使用代理服務器本地IP地址,如何「繞過本地地址的代理服務器」

  • 我想用ansible模塊安裝一些詹金斯插件: jenkins_plugin
  • 的插件正在從標準位置獲取:
    「updates_url」:「https://updates.jenkins-ci.org」所以需要通過去 代理。
  • 但是,基於IP地址的呼叫需要去本地jenkins 實例。

但是這失敗了。我測試了使用ip和localhost作爲jenkins實例的url。它看起來像所有去代理。

我該如何才能讓通過代理運行基於DNS的查詢?

此前我一直使用:

environment: 
    http_proxy: http://webproxy.ec.local:9090 
    https_proxy: http://webproxy.ec.local:9090 

,只是設置代理爲「」對任務重新使用本地主機地址在哪裏,但現在我需要同時使用本地主機和遠程網址。 而當然我不想要代理的本地主機!

failed: [localhost] (item=authorize-project) => { 
    "details": "HTTP Error 502: cannotconnect", 
    "failed": true, 
    "invocation": { 
     "module_args": { 
      "attributes": null, 
      "backup": null, 
      "content": null, 
      "delimiter": null, 
      "directory_mode": null, 
      "follow": false, 
      "force": false, 
      "force_basic_auth": true, 
      "group": "jenkins", 
      "http_agent": "ansible-httpget", 
      "jenkins_home": "/var/lib/jenkins", 
      "mode": "0644", 
      "name": "authorize-project", 
      "owner": "jenkins", 
      "regexp": null, 
      "remote_src": null, 
      "selevel": null, 
      "serole": null, 
      "setype": null, 
      "seuser": null, 
      "src": null, 
      "state": "present", 
      "timeout": 500.0, 
      "unsafe_writes": null, 
      "updates_expiration": 86400, 
      "updates_url": "https://updates.jenkins-ci.org", 
      "url": "http://localhost:8080", 
      "url_password": "admin", 
      "url_username": "admin", 
      "use_proxy": true, 
      "validate_certs": true, 
      "version": null, 
      "with_dependencies": true 
     } 
    }, 
    "item": "authorize-project", 
    "msg": "Cannot get CSRF" 

使用curl一些測試:

本地主機通話給出了一個502就像ansible一樣。

curl -X HEAD --proxy http://webproxy.ec.local:9090 -i localhost:8080 // 502 

curl -X HEAD --proxy http://webproxy.ec.local:9090 -i 10.251.130.45:8080 // FAIL, timeout 

curl -X HEAD -i http://10.251.130.45:8080 // 200 ok 

回答

0

NO_PROXY環境變量通過添加必要的例外解決這個問題。

environment: 
    http_proxy: http://webproxy.ec.local:9090 
    https_proxy: http://webproxy.ec.local:9090 
    no_proxy: 127.0.0.1, localhost, 10.251.*.* 

https://github.com/ansible/ansible/issues/31307