Portál AbcLinuxu, 2. listopadu 2025 08:15
- name: Add hosts to local inventory file /etc/ansible/hosts
local_action:
module: lineinfile
dest: /etc/ansible/hosts
backup: yes
regexp: "^{{host1}}"
line: "{{ item.ansiblehost }} ansible_host={{ item.ansiblehostip }}"
insertafter: '\[{{hostgroup}}\]'
state: present
with_items:
- { ansiblehost: '{{host1}}' , ansiblehostip: '{{host1IP}}' }
Všechny tasky proběhnou, kromě posledního - přidání hosta od invertory file. Výsledek je takovýto:
TASK [Add hosts to local inventory file /etc/ansible/hosts] **************************************************************************************************************************************
fatal: [xxx]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'item' is undefined
The error appears to have been in '/etc/ansible/vmware_clone_pokus.yml': line 137, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Add hosts to local inventory file /etc/ansible/hosts\n ^ here\n"}
with_items.
- name: Add hosts to local inventory file /etc/ansible/hosts
lineinfile:
dest: /etc/ansible/hosts
backup: yes
regexp: "^{{host1}}"
line: "{{ item.ansiblehost }} ansible\_host={{ item.ansiblehostip }}"
insertafter: '\[{{hostgroup}}\]'
state: present
with_items:
- { ansiblehost: "{{host1}}", ansiblehostip: "{{host1IP}}" }
delegate_to: localhost
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.