I'm not sure what value the with_items adds to this. Its all hardcoded values 
so why not hard code them into the parameters of the task?

 ansible.builtin.copy:
   src: "{{ lookup('ansible.builtin.first_found', findme) }}"
   dest: "/etc/security/access.conf"
   owner: "root"
   group: "root"
   mode: "0644"

Very clever use of first_found and your find_me vars definition.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Apr 18, 2023, at 11:39 AM, Michael DiDomenico <mdidomeni...@gmail.com> wrote:

i managed to come up with this, but seems like it could be cleaner

---
- name: copy pam etc/security/access.conf file
 vars:
   findme: |
     {%- set findme = [] -%}
     {%- for groupn in group_names -%}
       {{- findme.append('files/' + item.src + '_AG' + groupn) -}}
     {%- endfor -%}
     {{- findme.append("files/"+item.src+"_AH"+ansible_hostname) -}}
     {{- findme.append("files/"+item.src) -}}
     {{- findme | list -}}
#  debug:
#    msg: "{{ lookup('ansible.builtin.first_found', findme) }}"
 ansible.builtin.copy:
   src: "{{ lookup('ansible.builtin.first_found', findme) }}"
   dest: "/{{item.src}}"
   owner: "{{item.owner}}"
   group: "{{item.group}}"
   mode: "{{item.mode}}"
 with_items:
   - { src: "etc/security/access.conf", owner: "root", group: "root",
mode: "0644" }

On Tue, Apr 18, 2023 at 11:09 AM Michael DiDomenico
<mdidomeni...@gmail.com> wrote:

the below block is an example block i use in a few places to copy in
config files and select a host specific file if it exists.  not sure
if it's the best way, but it works for now.  what i'd like to do is
add in group selection as well.  ie if there's group file look for
that first

so above line 5 you could have
"files/{{ansible_local.baseos.ver}}/{{item.src}}_AG{{group}}"  but
clearly that wont work because there likely is more then on group
attached to a host.  so i need to try all the groups of a host and see
if there's a matching file.  the only way i can think to do it is to
create a second task that looks in the repository for a matching group
file and then registers a variable which i can include in the below
block above line 5

is there a better way?

 1 ---
 2 - name: copy pam etc/security/access.conf file
 3   vars:
 4     findme:
 5       - "files/{{item.src}}_AH{{ansible_hostname}}"
 6       - "files/{{item.src}}"
 7   ansible.builtin.copy:
 8     src: "{{ lookup('ansible.builtin.first_found', findme) }}"
 9     dest: "/{{item.src}}"
10     owner: "{{item.owner}}"
11     group: "{{item.group}}"
12     mode: "{{item.mode}}"
13   with_items:
14     - { src: "etc/security/access.conf", owner: "root", group:
"root", mode: "0644" }

--
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://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FCABOsP2P4XX2iNZODMfYSAJnhBZUJXFmhyVe2HigxfW-Rhd_Uog%2540mail.gmail.com&data=05%7C01%7Cwalter.rowe%40nist.gov%7Cf9881777aa77426a7b6d08db40231fee%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638174291823594841%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=xtnK%2FYpA8DapkwjWOnJ%2FufK4TLvXZCBop9%2FFIKSG2ng%3D&reserved=0.

-- 
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/3FD261BA-8FBB-4730-AC47-12E1777B2CF4%40nist.gov.

Reply via email to