Vagrant + Puppet:找不到部署命令后执行脚本

时间:2016-04-21 11:23:20

标签: vagrant puppet

我正在尝试使用Vagrant + Puppet部署后执行脚本:

  include nginx
  $nginx_conf_path = "${files_path}/${fqdn}/etc/nginx/sites-available"
  nginx::site { 'test.example.com.conf' :
    source => "${nginx_conf_path}/test.example.com.conf",
  }

  exec { 'install-letsencrypt.sh test.example.com':
    require => [Nginx::Site['test.example.com.conf'], Class['profile::ssl']],
    command => 'install-letsencrypt.sh test.example.com',
    path    => '/home/vagrant/bin/'
  }

ssl.pp

class profile::ssl { 

  file { "/home/vagrant/bin" :
    ensure => "directory",
    owner  => "vagrant",
    group  => "vagrant",
  }

  file { "/home/vagrant/bin/install-letsencrypt.sh":
    ensure => "present",
    owner  => "vagrant",
    group  => "vagrant",
    mode => 700,
    source => "puppet:///modules/example/shared/install-letsencrypt.sh"
  }
}

install-letsencrypt.sh

if [ ! -d "/opt/letsencrypt" ]; then
  sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
fi
# ...etc

profile::ssl有效,因为/home/vagrant/bin/install-letsencrypt.sh可用,但当我尝试exec傀儡时,我得到:

==> test.example.com: Error: Deploying Let's encrypt for test.mojjo.fr
==> test.example.com: /home/vagrant/bin/install-letsencrypt.sh: line 11: sudo: command not found
==> test.example.com: /home/vagrant/bin/install-letsencrypt.sh: line 14: mkdir: command not found
==> test.example.com: /home/vagrant/bin/install-letsencrypt.sh: line 17: sudo: command not found
==> test.example.com: /home/vagrant/bin/install-letsencrypt.sh: line 23: sudo: command not found
==> test.example.com: /home/vagrant/bin/install-letsencrypt.sh: line 25: sudo: command not found

我做错了什么?我尝试使用绝对可执行路径(/usr/bin/sudo而不是sudo),但它也不起作用。如果我ssh test.example.com并在那里运行它,它也有效,所以问题不在脚本中。

提前致谢

1 个答案:

答案 0 :(得分:0)

我有同样的问题来运行一些脚本,所以我做了

  exec { 'run-script':
    command => "bash -c 'install-letsencrypt.sh test.example.com'",
    ....
  }