LoginSignup
2
1

More than 5 years have passed since last update.

ChefとAnsibleにおけるファイル作成の比較

Last updated at Posted at 2018-08-21

ChefとAnsibleで、内容を指定したファイル作成を比較してみる。
/tmp/text.txtファイルに"foo\n"を設定する。
対象システムはUnix or Linux

Chef 例

fileリソースのcontent属性を使用する

file '/tmp/text.txt' do
  content "foo\n"
end
  • 必要にして十分。
  • ファイルを扱う専用リソースなので、他にも、オーナー、グループ、権限、バックアップなどに対応。

Ansible 例

---
- hosts: all
  tasks:

  - copy:
      content: |
        foo
      dest: /tmp/text.txt
  • copyモジュールにファイルの内容を設定する機能あったので例を更新。(2019/03)

参考
copy – Copies files to remote locations

蛇足 InSpec の例

Ruby DSLなのでChef like
ServerSpecでも同様という理解。

describe file('/tmp/test.txt') do
  its('content') { should eq "foo\n" }
end
2
1
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
2
1