bash - 木偶:“错误:无法从远程服务器检索目录”将代码添加到配置文件后
问题描述
我是puppet
新手。
我有一个功能puppet
安装(主和代理)。
我需要更新配置文件以检查两者certbot.timer
和nginx
systemd 服务是否都处于活动状态;如果是,添加renew_hook = service nginx reload
到/etc/letsencrypt/renewal/*.conf
文件中。
现在,我尝试将这些片段添加到现有配置文件中(一次一个):
exec { 'certbot_nginx' :
command => 'for file in $(find /etc/letsencrypt/renewal -type f); do if [ "$(grep "renew_hook = service nginx reload" $file)" != "renew_hook = service nginx reload" ]; then sed -i 's/\(\[renewalparams\]\)/\1\nrenew_hook = service nginx reload/' $file; fi; done',
onlyif => 'systemctl -q is-active certbot.timer && systemctl -q is-active nginx',
}
exec { "bash -c "if [ \"$(systemctl -q is-active certbot.timer && echo $?)\" = \"0\" ] && [ \"$(systemctl -q is-active nginx && echo $?)\" = \"0\" ]; then for file in $(find /etc/letsencrypt/renewal -type f); do if [ \"$(grep \"renew_hook = service nginx reload\" $file)\" != \"renew_hook = service nginx reload\" ]; then sed -i 's/\(\[renewalparams\]\)/\1\nrenew_hook = service nginx reload/' $file; fi; done; fi"" :
provider => shell,
command => 'bash -c "if [ \"$(systemctl -q is-active certbot.timer && echo $?)\" = \"0\" ] && [ \"$(systemctl -q is-active nginx && echo $?)\" = \"0\" ]; then for file in $(find /etc/letsencrypt/renewal -type f); do if [ \"$(grep \"renew_hook = service nginx reload\" $file)\" != \"renew_hook = service nginx reload\" ]; then sed -i 's/\(\[renewalparams\]\)/\1\nrenew_hook = service nginx reload/' $file; fi; done; fi"',
}
无论我做什么,我都会收到此错误(仅当这些片段在配置文件中时;否则puppet agent -t
将成功运行):
# puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Syntax error at 's' at /some/path/profile.pp:19:186 on node my.server.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
旁注
(1)傀儡代理版本:
# puppet --version
5.4.0
(2)傀儡服务器版本:
# puppetserver --version
puppetserver version: 2.8.0
(3) 服务器操作系统:Ubuntu 16.04.3 LTS
(4) 客户端操作系统:(Debian 9
我也遇到了错误Debian 10
。)
解决方案
尝试(也在@john bollinger的评论中提供):
exec { 'certbot_nginx' :
command => 'for file in $(find /etc/letsencrypt/renewal -type f); do if [ "$(grep "renew_hook = service nginx reload" $file)" != "renew_hook = service nginx reload" ]; then sed -i "s/\(\[renewalparams\]\)/\1\nrenew_hook = service nginx reload/" $file; fi; done',
onlyif => 'systemctl -q is-active certbot.timer && systemctl -q is-active nginx',
}
和:
exec { 'renew_hook = service nginx reload' :
provider => shell,
command => 'bash -c "if [ \"$(systemctl -q is-active certbot.timer && echo $?)\" = \"0\" ] && [ \"$(systemctl -q is-active nginx && echo $?)\" = \"0\" ]; then for file in $(find /etc/letsencrypt/renewal -type f); do if [ \"$(grep \"renew_hook = service nginx reload\" $file)\" != \"renew_hook = service nginx reload\" ]; then sed -i "s/\(\[renewalparams\]\)/\1\nrenew_hook = service nginx reload/" $file; fi; done; fi"',
}
这意味着您有一个字符串,例如:
'some command; sed 's/x/y/''
有关puppet lang 数据字符串的更多文档
在 Puppet 语言中有四种编写文字字符串的方法:
- 空话
- 单引号字符串
- 双引号字符串
- Heredocs
这意味着您的字符串将在第二个之后终止'
。
推荐阅读
- arrays - 从包含 $string 的数组中回显 url
- ios - 如何在 iOS 中使用 NSKeyedArchiver 将已写入文件系统的 Flutter 中的文件作为字符串读取?
- flutter - 如何使用 MockBloc 实现小部件测试?
- google-apps-script - 谷歌应用脚本获取谷歌幻灯片中一行的宽度和高度
- spring-boot - Spring-boot TransactionRequiredException:执行更新/删除查询
- android - Firebase 消息传递 FCM 在可配置的时间间隔内分发
- python-3.x - 如何从python在excel文件上添加一个空行
- javascript - 防止在路由查询参数更改时重新获取 api
- python - 点对点迭代后如何计算结果的总和,不包括重复
- ms-access - 更改每个访问对象中的表字段名称