0

I'm getting an error with a very simple play,

- name: add to environment                                                          
  lineinfile:                                                                       
    path: /etc/environment                                                          
    line: "{{ item }}"                                                              
    loop:                                                                           
      - "foo=1"                                                                     
      - "bar=2"

I simply want to add those lines to that file if they don't exist. The error I get is,

fatal: [10.1.38.15]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to have been in '/home/ecarroll/cp/ansible/roles/sandbox/tasks/main.yml': line 6, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n dest: /\n- name: add to environment\n ^ here\n"}

| improve this question | | | | |
2

You have mis-indented your loop directive. It's not an argument to lineinfile; it's a task setting:

- name: add to environment                                                          
  lineinfile:                                                                       
    path: /etc/environment                                                          
    line: "{{ item }}"                                                              
  loop:                                                                           
    - "foo=1"                                                                     
    - "bar=2"
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.