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 }
成功解决!