You want stdout_lines rather than stdout. The former is a list with new-lines removed. The latter is a possibly very long string with the complete output stream intact.

    - name: Append to all known_host files
      shell: cat /tmp/append >> {{ item }}
      loop:
        - '{{ known.stdout_lines }}'


On 5/23/24 9:07 AM, Dimitri Yioulos wrote:
Good day, all. I hope I'm not wearing out my welcome with too many questions.

In the following playbook, I first find any know_host file for any user on a particular system. I then copy a file with the list of additions to add to the known_hosts files. What I want to do is use the output of my register values to make changes to those know_host files, which my last play does. My iteration is wrong, though.

The playbook:

*---

- hosts: all
  gather_facts: false
  become: yes

  vars:
    script_path: <script>

  tasks:

    - name: Find known hosts
      shell: find /root /home -type f -name known_hosts
      register: known

    - name: Debug known_hosts paths
      debug:
        msg: "{{ known.stdout }}"

    - name: Set fact with known_hosts paths
      set_fact:
        known_hosts_paths: "{{ known.stdout_lines }}"

    - name: Upload entries for new known_hosts svn
      copy:
        src: append
        dest: /tmp/append
        owner: root
        group: root
        mode: u=rwx,g=rw,o=rw

    - name: Append to all known_host files
      shell: cat /tmp/append >> {{ item }}
      loop:
        - '{{ known.stdout }}'*

The output of the first play:

*ok: [myhost] =>
  msg: |-
    /root/.ssh/known_hosts
    /home/user1/.ssh/known_hosts
    /home/ user2/.ssh/known_hosts
    /home/ user3/.ssh/known_hosts
    /home/ user4/.ssh/known_hosts*

How do I make that last play work? --
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/84e78306-66cf-4d86-8b45-d1c4816c598en%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/84e78306-66cf-4d86-8b45-d1c4816c598en%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Todd

--
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/4b07b147-2d6b-40d4-aa6f-a0e385893c6a%40gmail.com.

Reply via email to