-
name: Testen des lineinfile Modules
hosts: d127test
gather_facts: yes
become: yesvars_files:
tasks:
-
name: Filtern der IP-Adresse von en6
ansible.builtin.debug:
msg: “{{ ansible_facts[‘en6’][‘ipv4’][‘address’] }}”
when: “‘en6’ in ansible_facts”
register: ip -
name: Füge Host in /etc/hosts ein
ansible.builtin.lineinfile:
path: /etc/hosts
regexp: “{{ip}}”
insertafter: ‘[B,b]ackup’
line: “{{ip}} {{inventory_hostname}}_rub.backup.dc {{inventory_hostname}}_rub”
state: present
when: “‘en6’ in ansible_facts”
-
i become:
fatal: [d127test]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘list object’ has no attribute ‘address’. ‘list object’ has no attribute ‘address’\n\nThe error appears to be in ‘/home/mschm103/ansiblehome/ms_test_rubrik.yml’: line 11, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Filtern der IP-Adresse von en6\n ^ here\n”}