Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created August 19, 2013 05:21
Show Gist options
  • Save hnakamur/6265936 to your computer and use it in GitHub Desktop.
Save hnakamur/6265936 to your computer and use it in GitHub Desktop.
First add localhost to your inventory file (ex. /etc/ansible/hosts or ~/.ansible/hosts) and then run ansible-playbook ansible-directories.yml
- hosts: localhost
connection: local
vars:
role: common
tasks:
- name: create directories for ansible files.
file: path={{ item }} state=directory
with_items:
- group_vars
- host_vars
- roles/{{ role }}/tasks
- roles/{{ role }}/handlers
- roles/{{ role }}/templates
- roles/{{ role }}/files
- roles/{{ role }}/vars
@hnakamur
Copy link
Author

Passing Variables On The Command Line を参考に以下のように--extra-varsオプション付きで実行するとroleの値を上書きできました。

ansible-playbook --extra-vars '{"roles":["common", "webservers", "dbservers"]}' ansible-directories.yml

--extra-vars無しだと、ymlに書かれたroleで実行されました。

細かいですけど変数名はroleよりrolesのほうがいいですね。

@shirou
Copy link

shirou commented Aug 19, 2013

ああ、 --extra-vars で上書きという手もありますね確かに。
role/rolesに関してはrolesに直しました。

@hnakamur
Copy link
Author

ありがとうございます。私の実行例もrole→rolesに編集しました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment