loading...

small error related to quote and indent in ansible playbook loop

icy1900 profile image Roy Updated on ・1 min read
- name: set name resolve                                                                                                                                                                                         
    blockinfile:                                                                                                                                                                                                   
      path: /etc/hosts                                                                                                                                                                                             
      block: |                                                                                                                                                                                                     
        {{ hostvars[item]['ansible_facts']['eth1']['ipv4']['address'] }} cluster-endpoint                                                                                                                          
      loop: "{{ groups[master] }}" 

The task includes an option with an undefined variable. The error was: 'master' is undefined

- name: set name resolve                                                                                                                                                                                         
    blockinfile:                                                                                                                                                                                                   
      path: /etc/hosts                                                                                                                                                                                             
      block: |                                                                                                                                                                                                     
        {{ hostvars[item]['ansible_facts']['eth1']['ipv4']['address'] }} cluster-endpoint                                                                                                                          
      loop: "{{ groups[`master`] }}" 

The task includes an option with an undefined variable. The error was: 'item' is undefined

the indent level of loop directive is wrong

{{ }} 中,字符串(非变量名,filter 名,test名)需要引用起来,以与变量名区分

Posted on by:

Discussion

pic
Editor guide