Q: puppet自動部署安裝VSFTP後,客戶端需要拉取兩次才能安裝、啓動服務
[root@agent1 mnt]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent1.yu.net
Info: Applying configuration version '1525403897'
Error: Could not start Service[vsftpd]: Execution of '/sbin/service vsftpd start' returned 1: vsftpd: unrecognized service
Error: /Stage[main]/Vsftpd/Service[vsftpd]/ensure: change from stopped to running failed: Could not start Service[vsftpd]: Execution of '/sbin/service vsftpd start' returned 1: vsftpd: unrecognized service
Notice: /Stage[main]/Vsftpd/Package[vsftpd]/ensure: created
Notice: Finished catalog run in 8.40 seconds
A:
1.第一次拉取資源顯示上面錯誤。自己service啓動成功。
[root@agent1 mnt]# service vsftpd start
Starting vsftpd for vsftpd: [ OK ]
2.將vsftpd卸載,重新用puppet安裝
[root@agent1 mnt]# rpm -e vsftpd
[root@agent1 mnt]# service vsftpd status
vsftpd: unrecognized service
//卸載成功
3.重新使用puppet安裝、啓動。
[root@agent1 mnt]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent1.yu.net
Info: Applying configuration version '1525403897'
Error: Could not start Service[vsftpd]: Execution of '/sbin/service vsftpd start' returned 1: vsftpd: unrecognized service
Error: /Stage[main]/Vsftpd/Service[vsftpd]/ensure: change from stopped to running failed: Could not start Service[vsftpd]: Execution of '/sbin/service vsftpd start' returned 1: vsftpd: unrecognized service
Notice: /Stage[main]/Vsftpd/Package[vsftpd]/ensure: created
Notice: Finished catalog run in 6.12 seconds
再次出錯!
4.再次使用puppet
[root@agent1 mnt]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent1.yu.net
Info: Applying configuration version '1525403897'
Notice: /Stage[main]/Vsftpd/Service[vsftpd]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Vsftpd/Service[vsftpd]: Unscheduling refresh on Service[vsftpd]
Notice: Finished catalog run in 0.35 seconds
[root@agent1 mnt]# service vsftpd status
vsftpd (pid 26895) is running...
成功啓動!
總結:爲何無法一次成功?需要puppet拉去兩次?
5.嘗試更改執行服務方式,改爲執行命令
1 class vsftpd{
2 yumrepo {"Server":
3 descr => "Server repo",
4 baseurl => "file:///mnt/dvd",
5 gpgcheck=>"0",
6 enabled =>"1";
7
8 }
9
10 package {"vsftpd":
11 ensure=>installed,
12 require=>Yumrepo["Server"];
13 }
14
15
16 exec {"vsftpd":
17 command=>'/etc/init.d/vsftpd start',
18 owner =>'root',
19 path=>["/bin/sbin/vsftpd"];
20 }
或者
exec {"/etc/init.d/vsftpd start":
owner =>'root';
}
//以上命令執行語法格式有問題,正確格式如下:
exec{'vsftpd':
path =>'/bin:/sbin:/usr/bin:/usr/sbin',
command => '/etc/init.d/vsftpd start',
}
並不好使!報錯
[root@agent2 ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter owner on Exec[vsftpd] at /etc/puppet/modules/vsftpd/manifests/init.pp:20 on node agent2.yu.net
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
6.更改服務執行位置到vim /etc/puppet/manifests/site.pp
1 node 'default' {
2 include vsftpd
3
4 service {"vsftpd":
5 ensure => running;
6 }
10 }
報錯:
[root@agent2 ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for agent2.yu.net
Info: Applying configuration version '1525659052'
Error: Could not start Service[vsftpd]: Execution of '/sbin/service vsftpd start' returned 1: vsftpd: unrecognized service
Error: /Stage[main]/Main/Node[default]/Service[vsftpd]/ensure: change from stopped to running failed: Could not start Service[vsftpd]: Execution of '/sbin/service vsftpd start' returned 1: vsftpd: unrecognized service
Notice: /Stage[main]/Vsftpd/Package[vsftpd]/ensure: created
Notice: Finished catalog run in 11.69 seconds
[root@agent2 ~]#
和之前一樣的錯誤!
7.改爲執行命令
1 node 'default' {
2 include vsftpd
3
4 exec {"/etc/init.d/vsftpd start":
5 owner =>'root';
6 }
7
8 }
~
還是報錯!
[root@agent2 ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter owner on Exec[/etc/init.d/vsftpd start] at /etc/puppet/manifests/site.pp:6 on node agent2.yu.net
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
8.經查找資料發現是依賴關係問題,puppet中的多個命令並不會按順序依次執行,可能會跳躍執行,所以啓動服務命令在安裝命令之前執行了,造成了錯誤,第二次拉取時,因爲已經安裝了,跳過安裝步驟,直接執行,所以就成功了。如果想解決問題,應當在服務之間加上依賴:
18 package {"vsftpd":
19 ensure=>present,
20 name =>vsftpd,
21
22 }-> //次序連;作用和require/before類似
23 service {"vsftpd":
24 ensure =>running,
25 name =>vsftpd,
26 require=>Package['vsftpd'], //本模塊需要在package['vsftpd']模塊之後執行
27 }
成功解決!