11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ansible Roleのスケルトンを作成するワンライナー

Last updated at Posted at 2014-10-26

setuptoolsのコマンドを定義したり、Ansibleのタスク化してみたり、他にもやり方はあると思う。自分には一回入力+シェルでのコマンド履歴検索というのが一番手軽に感じたのでしばらくはこれでいこうかと。

ansible_role_oneliner
$ (role=common; mkdir -p $role; cd $role && for d in templates files; do mkdir -p $d && touch $d/.gitkeep; done; for d in tasks handlers vars defaults meta; do mkdir -p $d && touch $d/main.yml; done)

追記

横の人が「処理の共通化ぐらいしろボケ」って言いつつ、書き直してくれました。

ansible_role_oneliner2
$ (role=common; mkdir -p $role; cd $role && mk() { mkdir -p $1; touch $1/$2; }; for d in templates files; do mk $d .gitkeep; done; for d in tasks handlers vars defaults meta; do mk $d main.yml; done)

こちらはeval使ってもうちょい短くしたバージョン。本人曰く「処理が分かりにくくなるからevalはやめた方がいいかもな」とのこと。

ansible_role_oneliner_eval
$ (role=common; mkdir -p $role; cd $role && mk() { mkdir -p `eval echo $1`; touch `eval echo $1/$2`; }; mk "{templates,files}" .gitkeep; mk "{tasks,handlers,vars,defaults,meta}" main.yml)

さらに追記

ansible-galaxy initという手があるらしい...
http://qiita.com/tumf/items/546a578cb05237ec8356#comment-0c3b2388fc5531c8dcd7

.gitkeepまでは作ってくれないから(震え

ということで、これとこれを組み合わせてこうじゃ!

ansilbe_role_oneliner3
$ (role=roles/common; ansible-galaxy init $role && for d in templates files; do touch $role/$d/.gitkeep; done)
11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?