DEV Community

Roy
Roy

Posted on • Updated on

small error related to quote and indent in ansible playbook loop

- 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名)需要引用起来,以与变量名区分

Top comments (0)