我正在尝试启用代理和反向代理,以便所有到达我的Web服务器的请求都被转移到appserver。我在Ubuntu EC2实例上使用ansible。我收到错误消息:
致命:[网络服务器]:失败! => {“已更改”:false,“ msg”:“ AnsibleUndefinedVariable:'ansible.vars.hostvars.HostVarsVars对象'没有属性'ansible_eth0'”}
我该如何解决ansible.vars.hostvars.HostVarsVars对象'没有属性
尝试hostvars获取IP地址,但失败了
我的proxy.conf文件:
ProxyPass / http://{{ hostvars['appserver']['ansible_eth0']['ipv4']['address'] }}:8000/
ProxyPassReverse / http://{{ hostvars['appserver']['ansible_eth0']['ipv4']['address'] }}:8000/
我的剧本
---
- hosts: webserver
become: yes
gather_facts: yes
roles:
- webserver
roles/task.main.yml
- name: "Installing Apache"
apt: name{{ item }}
with_item :
- aoache2
- name: "Enable Proxy server"
apache2_module: name=proxy_http
- name: "Adding Proxy Configuration"
template: src=/etc/ansible/roles/webserver/files/proxy.conf dest=/etc/apache2/conf-available owner=root group=root mode=0755
notify:
- enable-proxy-config
我的处理程序/roles/handlers/main.yml
- name: enable-proxy-config
shell: a2enconf proxy.conf
notify:
- restart-apache