Skip to content

Instantly share code, notes, and snippets.

@drybjed
Last active August 29, 2015 14:04
Show Gist options
  • Save drybjed/b990662e9c207e47650d to your computer and use it in GitHub Desktop.
Save drybjed/b990662e9c207e47650d to your computer and use it in GitHub Desktop.
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [tyrion]
TASK: [Create workdir] ********************************************************
ok: [tyrion]
TASK: [Create user homes] *****************************************************
ok: [tyrion] => (item={'owner': 'root'})
ok: [tyrion] => (item={'owner': u'drybjed', 'dirs': ['user1', 'user2']})
TASK: [Create directories] ****************************************************
fatal: [tyrion] => could not find 'dirs' key in iterated item '{'owner': 'root'}'
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/home/drybjed/test_mkdir.retry
tyrion : ok=3 changed=0 unreachable=1 failed=0
---
- hosts: all
sudo: True
vars:
workdir: '/tmp/workdir'
directories:
- owner: 'root'
- owner: '{{ ansible_ssh_user }}'
dirs: [ 'user1', 'user2' ]
tasks:
- name: Create workdir
file: state=directory path={{ workdir }}
- name: Create user homes
file: state=directory path={{ workdir + '/' + item.owner }}
owner={{ item.owner }} group={{ item.owner }}
with_items: directories
- name: Create directories
file: state=directory path={{ workdir + '/' + item.0.name + '/' + item.1 }}
owner={{ item.0.owner }} group={{ item.0.owner }}
with_subelements:
- '{{ directories }}'
- 'dirs'
when: item.0.dirs is defined and item.0.dirs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment