until now i believed that the file lookup only bites when the file is 
available (ssh key in this example), but instead it fails if it not exists. 
any hints on the reason of this strange behaviour?

error message:

TASK [manage_ldap_users : authorized_key] 
*********************************************************************************************************************************************************************
 [WARNING]: Unable to find 'files/keys/kwo.key.pub' in expected paths (use 
-vvvvv 
to see paths)

fatal: [TESTHOST]: FAILED! => {}

MSG:

An unhandled exception occurred while running the lookup plugin 'file'. 
Error was a <class 'ansible.errors.AnsibleError'>, original message: could 
not locate file in lookup: files/keys/user2.key.pub
Enter code here...

play:
- block:
       - name: enable aml users
         blockinfile:
                    dest: /etc/security/user
                    backup: no
                    marker: "*** {mark} ***"
                    marker_begin: "BEGIN - ADDED WITH ANSIBLE - {{ 
item.name }}"
                    marker_end: "END - ADDED WITH ANSIBLE - {{ item.name }}"
                    state: "{{ item.state }}"
                    block: |
                         {{ item.name }}:
                                 SYSTEM = "LDAP"
                                 registry = LDAP
         with_items: "{{ aml_users }}"

       - name: prepare homes
         include_tasks: "{{ role_path }}/tasks/create_homes.yml"
         with_items: "{{ aml_users }}"
  when: create_aml_users.stat.exists
Enter code here...

included task:

- shell: "lsuser -R LDAP -a pgrp {{ item.name }} | awk '{print $2}' | cut 
-d= -f2"
  register: primary_group
  failed_when: false
  changed_when: false

- shell: "lsuser -R LDAP -a home {{ item.name }} | awk -F= '{print $2}'"
  register: home_dir
  failed_when: false
  changed_when: false

- file:
      path: '{{ home_dir.stdout | default("/home/"+item.name) }}'
      state: directory
      owner: "{{ item.name }}"
      group: '{{ primary_group.stdout | default(item.name) }}'
  when: "item.state == 'present'"

- file:
      path: '{{ home_dir.stdout | default("/home/"+item.name) }}'
      state: absent
      owner: "{{ item.name }}"
      group: '{{ primary_group.stdout | default(item.name) }}'
  when: "item.state == 'absent'"

- authorized_key:
                user: "{{ item.name }}"
                state: "{{ item.state }}"
                key: "{{ lookup('file', 'files/keys/'+ item.name + 
'.key.pub') }}"
  when: "item.state == 'present'"
Enter code here...

vars file structure:
aml_users:
         - name: "user1"
           comment: "some name"
           state: present
         - name: "user2"
           comment: "some name"
           state: present
         - name: "user3"
           comment: "some name"
           state: present
         ...



-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b1c30e24-d0dd-40a8-9db5-f48a20ee12a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to