0
-name: SFTP | inbox
file: path="{{ item.home }}/{{ item.username }}{{ item.suffix1 }}/{{ item.inbox }}" mode=0775 owner="{{ item.username }}" group="{{ web_user }}" state=directory
with_items: "{{ clients }}"
when: suffix1 is defined
 
-name: SFTP | outbox 
file: path="{{ item.home }}/{{ item.username }}{{ item.suffix1 }}/{{ item.outbox }}" mode=0775 owner="{{ item.username }}" group="{{ web_user }}" state=directory 
with_items: "{{ clients }}" 
when: suffix1 is defined
 
TASK [sftp-user : SFTP | inbox **************************** 
skipping: [server1] => (item={u'username': u'test1', u'home': u'/home/test1', u'inbox': u'Inbox', u'outbox': u'Outbox'}) 
skipping: [server1] => (item={u'username': u'test2', u'inbox': u'Inbox', u'outbox': u'Outbox', u'home': u'/home/test2', u'suffix2': u'_right', u'suffix1': u'_left'}) 
skipping: [server1] => (item={u'username': u'test3', u'home': u'/home/test3', u'inbox': u'Inbox', u'outbox': u'Outbox'})
 
TASK [sftp-user : SFTP | outbox **************************** 
skipping: [server1] => (item={u'username': u'test2', u'inbox': u'Inbox', u'outbox': u'Outbox', u'home': u'/home/test2', u'suffix2': u'_right', u'suffix1': u'_left'}) 
skipping: [server1] => (item={u'username': u'test1', u'home': u'/home/test1', u'inbox': u'Inbox', u'outbox': u'Outbox'}) 
skipping: [server1] => (item={u'username': u'test3', u'home': u'/home/test3', u'inbox': u'Inbox', u'outbox': u'Outbox'})
 
clients:
 - username: test1 
   home: /home/test1 
   outbox: Outbox 
   inbox: Inbox
 
 - username: test2 
   home: /home/test2 
   outbox: Outbox 
   inbox: Inbox 
   suffix1: _left 
   suffix2: _right
 
 - username: test3 
   home: /home/test3 
   outbox: Outbox 
   inbox: Inbox

There is an array with clients, some clients have a suffix for a folder, some do not. Example: all clients have suffixes - folders are created if the first client does not have a suffix, and the second has suffix - folders creation is skipped. Skipped the first client and create the second client. How to solve this problem,since all clients in this code are skipped, please tell me?

1 Answer 1

1

item.suffix1 has to be tested. The condition is evaluated on each iteration

when: item.suffix1 is defined
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, I spent 2 days working on this problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.