Dengan menggunakan editor teks (vim,
emacs, nano) buatlah sebuah file dengan nama user-absent.pp dengan isi sebagai
berikut:
# /root/examples/user-absent.pp
user {'ridlo':
ensure => absent,
}
Simpan dan tutup editor, kemudian
jalankan dengan perintah :
#
puppet apply /root/examples/user-absent.pp
notice:
/Stage[main]//User[ridlo]/ensure: removed
notice:
Finished catalog run in 0.07 seconds
Lalu jalankan perintah lagi dengan
perintah :
#
puppet apply /root/examples/user-absent.pp
notice:
Finished catalog run in 0.03 seconds
Manifests
Program puppet disebut juga
manifests, dan menggunakan file extension .pp. Core dari bahasa Puppet disebut resource
declaration. Sebuah resource declaration mendeskripsikan desired
state untuk satu resource.
# /root/examples/file-1.pp
file {'testfile':
path => '/tmp/testfile',
ensure => present,
mode => 0640,
content => "I'm a test file.",
}
Kemudian jalankan perintah
#
puppet apply /root/examples/file-1.pp
notice:
/Stage[main]//File[testfile]/ensure: created
notice:
Finished catalog run in 0.05 seconds
#
cat /tmp/testfile
I'm
a test file.
#
ls -lah /tmp/testfile
-rw-r-----
1 root root 16 Feb 23 13:15 /tmp/testfile
Jika kita merubah mode dan
mengaplikasikan ke manifests lagi. Lakukan perintah
#
chmod 0666 /tmp/testfile
#
puppet apply /root/examples/file-1.pp
notice:
/Stage[main]//File[testfile]/mode: mode changed '0666' to '0640'
notice:
Finished catalog run in 0.04 seconds
Ok, sekarang kita coba bermain
dengan tipe file yang lain.
# /root/examples/file-2.pp
file {'/tmp/test1':
ensure => file,
content => "Hi.",
}
file {'/tmp/test2':
ensure => directory,
mode => 0644,
}
file {'/tmp/test3':
ensure => link,
target => '/tmp/test1',
}
user {'ridlo':
ensure => absent,
}
notify {"I'm notifying
you.":}
notify {"So am I!":}
Eksekusi:
#
puppet apply /root/examples/file-2.pp
notice:
/Stage[main]//File[/tmp/test1]/ensure: created
notice:
/Stage[main]//File[/tmp/test3]/ensure: created
notice:
/Stage[main]//File[/tmp/test2]/ensure: created
notice:
So am I!
notice:
/Stage[main]//Notify[So am I!]/message: defined 'message' as 'So am I!'
notice:
I'm notifying you.
notice:
/Stage[main]//Notify[I'm notifying you.]/message: defined 'message' as 'I'm
notifying you.'
notice:
Finished catalog run in 0.05 seconds
Apa yang terjadi?
Keren bukan?
Nilai Ensure Baru, State Berbeda
Atribut ensure adalah atribut yang spesial. Berikut adalah type2nya:
Atribut ensure adalah atribut yang spesial. Berikut adalah type2nya:
- Sebagai normal file (ensure => file)
- Sebagai directory (ensure => directory)
- Sebagai symlink (ensure => link)
- Selain di atas (ensure => present)
- Tidak sebagai apa-apa (ensure => absent).
# ls -lah /tmp/test* -rw-r--r-- 1
root root 3 Feb 23 15:54 test1 lrwxrwxrwx 1 root root 10 Feb 23 15:54 test3
-> /tmp/test1 /tmp/test2: total 16K drwxr-xr-x 2 root root 4.0K Feb 23 16:02
. drwxrwxrwt 5 root root 4.0K Feb 23 16:02 .. # cat /tmp/test3 Hi.
0 komentar:
Posting Komentar