0
3

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でディレクトリがあるか判別して作成する処理

Last updated at Posted at 2017-06-15

概要

Ansibleでディレクトリがないか判別して、もしなければ作成する処理を書いてみました。

メモ

resultで返り値を返してあげて、その値を元にwhenで判別してます。
resultの値はstdoutで文字列として読み取ってます。

もっとかっこいい方法あるかもですが。

state: directoryでディレクトリがなければ作成になります。

ソースコード

- name: make dir
  file:
    path: /tmp/test
    state: directory
    owner: root
    group: root
    mode: 0700
  when: result.stdout == "1"

0
3
2

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
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?