Ansible使用代理上网

直接在task中定义:

---
- hosts: all
  remote_user: root
  tasks:
    - apt: name=cobbler state=installed
      environment:
        http_proxy: http://proxy.example.com:8080

在task中调用变量:

---
- hosts: all
  remote_user: root

  # here we make a variable named "proxy_env" that is a dictionary
  vars:
    proxy_env:
      http_proxy: http://proxy.example.com:8080

  tasks:
    - apt: name=cobbler state=installed
      environment: "{{proxy_env}}"

在playbook中定义:

---
- hosts: testhost

  roles:
     - php
     - nginx

  environment:
    http_proxy: http://proxy.example.com:8080

在组变量中定义:

---
# file: group_vars/boston

ntp_server: ntp.bos.example.com
backup: bak.bos.example.com
proxy_env:
  http_proxy: http://proxy.bos.example.com:8080
  https_proxy: http://proxy.bos.example.com:8080

使用lineinfile模块在被管主机配置文件/etc/environment中定义:

http_proxy="http://proxy.bos.example.com:8080"
https_proxy="http://proxy.bos.example.com:8080"
posted @ 2020-10-28 17:44  Varden  阅读(1463)  评论(0编辑  收藏  举报