I have a playbook where i first [Play 1] add dynamic host to group 
"desthosts" 

In Play 2 I append a string variable "storerecords" with filenames. Sample 
playbook below:

In Play 3 I try to remove duplicate entries in "storerecords" variable 
where i get the error.

---
- name: Play 1
  hosts: localhost
    - addhost:
          name: "{{ item }}"
          group: desthosts
      with_items:
          - "{{ SourceFiles.split(',') }}"
 


- name: Play 2
  hosts: desthosts
    - set_fact:
        storerecords: "{{ storerecords  | default('') + item + '\n' }}"
      with_fileglob:       - "{{ playbook_dir }}/tmpfiles/*"




- name: Play 3
  hosts: localhost
    - local_action: lineinfile line="{{ storerecords }}" path="{{ 
playbook_dir }}/files/tricky.txt" create=yes

    - set_fact:
        storerecords: "{{ storerecords.split('\n') | unique | select | 
join('\n') }}"


Error running the playbook is:

TASK [lineinfile] 
*******************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an 
undefined variable. The error was: 'storerecords' is undefined\n\nThe error 
appears to be in '/app/scripts/deploy.yml': line 1277, column 6, but 
may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe 
offending line appears to be:\n\n\n   - local_action: lineinfile line=\"{{ 
storerecords }}\" path=\"{{ playbook_dir }}/files/tricky.txt\" create=yes\n 
    ^ here\nWe could be wrong, but this one looks like it might be an issue 
with\nmissing quotes. Always quote template expression brackets when 
they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo 
}}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}


Can you please suggest how I can get the value of storerecords in from 
desthost to Play 3 localhost ?


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/012bd2cf-8635-44f0-9554-caaf4c50bafd%40googlegroups.com.

Reply via email to