为什么我的主机在更新后会停止工作?

时间:2020-01-09 10:03:13

标签: ansible

这是我脚本的一部分。更新后,它无法正常工作。更新前一切正常。 我认为“ with_items”语法存在问题

此处main.yml

- hosts: etckeeper-servers
  become: yes
  gather_facts: True

- hosts: etckeeper-clients
  become: yes
  gather_facts: True
  pre_tasks:
    - import_tasks: tasks/generate_key.yml
      when: uninstall_etckeeper == false
- name: Create system accounts
  user:
    name: git-{{ hostvars[item]['ansible_hostname'] }}
    home: /home/git-{{ hostvars[item]['ansible_hostname'] }}
    state: present
  with_items: "{{ groups['etckeeper-clients'] }}"

输出

"msg": "The task includes an option with an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_hostname'\n\nThe error appears to have been in '/var/lib/awx/projects/_7__etckeeper/roles/etckeeper_server/tasks/install_etckeeper_centos.yml': line 1, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Create system accounts\n  ^ here\n",

但是如果我手动检查变量,我就有主机名

TASK [debug] *******************************************************************
ok: [192.168.4.92] => {
    "ansible_hostname": "pmxnvr1"
}

0 个答案:

没有答案