Hi all,

So I'm trying to write to a local file from my ansible server based off
information I've gotten from my inventory hosts.  For some reason, it keeps
creating the file ON the inventory host instead of my ansible server.  Here
is my playbook:

---
- hosts: ALL_LINUX
  become: yes
  vars_files:
    - vars.yml

  vars:
    - SVR: "rhel.svr"
    - WKSTN: "rhel.wkstn"

  tasks:
    - name: Make sure files exist
      file:
        path: "{{ item }}"
        state: touch
      with_items:
        - "{{ SVR }}"
        - "{{ WKSTN }}"

    - name: Zero out files
      shell: cat /dev/null > "{{ item }}"
      with_items:
        - "{{ SVR }}"
        - "{{ WKSTN }}"
      delegate_to: localhost

    - name: Workstation or Server?
      shell: cat /etc/redhat-release | awk '{print $5}'
      register: rh_type
      tags: name

    - name: "Find rhel servers"
      lineinfile:
        dest: "{{ SVR }}"
        line: "{{ inventory_hostname }}"
        create: yes
        insertafter: EOF
      delegate_to: localhost
      when: rh_type.stdout == "Server"
      with_items: "{{ ansible_play_hosts }}"

    - name: "Find rhel workstations"
      lineinfile:
        dest: "{{ WKSTN }}"
        line: "{{ inventory_hostname }}"
        create: yes
        insertafter: EOF
      delegate_to: localhost
      when: rh_type.stdout == "Workstation"
      with_items: "{{ ansible_play_hosts }}"

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAHKi8CgrQ9KZoT1ViiPBuAr7UrwuUQ54DZc%3DDSnbZq3-Q7M%2B4Q%40mail.gmail.com.

Reply via email to