YAML 文件 (nsupdate.yml)
这是用于在远程服务器上安装多个包的 yaml 文件。
- hosts: nsupdate
remote_user: root
roles:
- postfix
- nginx
- certbot
- bind9
- postgresql
- nsupdate_info
主机文件
这是主机文件,其中提到了远程服务器IP
[nsupdate]
101.50.x.x (host IP Address)
收到错误 当我运行此剧本时,收到错误,即未定义变量“nsupdate”。但是,我已经在主机文件中定义了它。
[root@games ansible-nsupdate.info]# ansible-playbook nsupdate.yml
PLAY [nsupdate] **********************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [101.50.x.x]
TASK [postfix : Install Postfix] *****************************************************************************************************************************
ok: [101.50.x.x]
TASK [postfix : Install Postfix configuration] ***************************************************************************************************************
failed: [101.50.x.x] (item={u'dest': u'/etc/postfix/main.cf', u'src': u'main.cf.j2'}) => {"ansible_loop_var": "item", "changed": false, "item": {"dest": "/etc/postfix/main.cf", "src": "main.cf.j2"}, "msg": "AnsibleUndefinedVariable: 'nsupdate' is undefined"}
PLAY RECAP ***************************************************************************************************************************************************
101.50.x.x : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
收到的错误在此任务文件中
这是安装 Postfix 包的任务文件。
main.yml
- name: Install Postfix
apt:
pkg: [ "postfix", "libsasl2-modules" ]
install_recommends: false
- name: Install Postfix configuration
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: 0644
with_items:
- { src: "main.cf.j2", dest: "/etc/postfix/main.cf" }
- { src: "header_check.j2", dest: "/etc/postfix/header_check" }
- { src: "sender_canonical_maps.j2", dest: "/etc/postfix/sender_canonical_maps" }
notify: reload postfix
谁能建议如何解决此错误/问题。