Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

puppet tries to create vhost before nginx is installed? #610

Closed
tgallant opened this issue Apr 20, 2015 · 15 comments
Closed

puppet tries to create vhost before nginx is installed? #610

tgallant opened this issue Apr 20, 2015 · 15 comments
Labels
bug Something isn't working needs-feedback Further information is requested

Comments

@tgallant
Copy link

puppet file:

Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }

class {'nginx': }

nginx::resource::vhost { 'static-app':
  www_root => '/app',
}
Vagrant: 1.7.2
Puppet: 3.7.4
puppet-nginx(and dependencies): pulled from master branch on github

I am a puppet noob and I'm having a hard time figuring this out.

I am using vagrant with puppet as the provisioner. When I run vagrant up, it goes through the steps but always fails at:

Error: Could not set 'file' on ensure: No such file or directory - /etc/nginx/sites-available/static-app.conf20150420-1811-gd4k2p.lock

From my googling it seems that this error is caused when the parent directory doesn't exist.

a few lines after the error I get this:

 ==> default: Notice: /Stage[main]/Nginx::Config/File[/etc/nginx/nginx.conf]/content: content changed '{md5}f7984934bd6cab883e1f33d5129834bb' to '{md5}c56373a1bb1120304dbba46e017b22a6'
==> default: Notice: /Stage[main]/Nginx::Config/File[/etc/nginx/conf.mail.d]/ensure: created
==> default: Notice: /Stage[main]/Nginx::Config/File[/etc/nginx/sites-enabled]/ensure: created

Looks to me that the vhost is being created before the nginx directory.

am i doing something wrong here?

@3flex
Copy link
Contributor

3flex commented May 7, 2015

@tgallant in the lines after your error the directory /etc/nginx/sites-available isn't shown as being created. Can you find that line and see if it's being created before or after the error?

@3flex 3flex added needs-feedback Further information is requested bug Something isn't working labels May 7, 2015
@SamStonehouse
Copy link

Also getting this issue, will update if I figure out what's going on -

Edit:

Looks like mine was caused by using 'include nginx' but is fine with 'class { 'nginx': }' Is this expected?

Edit 2:

It's now happening sometimes and not others

@SamStonehouse
Copy link

Believe I've fixed my issues by adding

Class['::nginx::config'] -> Nginx::Resource::Vhost <| |>

below

Class['::nginx::package'] -> Class['::nginx::config'] ~> Class['::nginx::service']

in init.pp of the nginx module

@3flex
Copy link
Contributor

3flex commented May 19, 2015

Looks like #624 which was caused by a change in puppetlabs-concat.

If you can test the branch proposed in #624 and reply to that PR with your results that would be extremely helpful. Thanks!

@SamStonehouse
Copy link

Using that repo with my current setup gives the following warnings

==> default: Warning: Scope(Concat::Fragment[localhost-header]): The $ensure parameter to concat::fragment is deprecated and has no effect.
==> default: Warning: Scope(Concat::Fragment[localhost-footer]): The $ensure parameter to concat::fragment is deprecated and has no effect.
==> default: Warning: Scope(Concat::Fragment[851f2f1ae466fdec0f580031f05917d8]): The $ensure parameter to concat::fragment is deprecated and has no effect.
==> default: Warning: Scope(Concat::Fragment[fd0b234173aed6ab4786b7032214c741]): The $ensure parameter to concat::fragment is deprecated and has no effect.

But it does seem to work

@3flex
Copy link
Contributor

3flex commented May 26, 2015

This should be fixed with the merge of #624.

@tgallant can you confirm?

@nfourteen
Copy link

Vagrant 1.8.1
Puppet 3.4.3
Concat 2.1.0
Nginx 0.3.0
Apt 2.2.2

I've run into this same issue and can't figure out what's going on. I tried setting nginx::config::vhost_purge: false and nginx::config::confd_purge: false thinking they might be deleting the directories entirely, but still got the error. Furthermore, I can vagrant ssh into the machine after this error occurs and both /etc/nginx/sites-available and /etc/nginx/sites-enabled directories do exist. It still appears that the vhost file is being added before the directory is created (see vagrant debug log below). For anyone who runs into this error a workaround is to run vagrant reload --provision after the initial vagrant up. Note: vagrant destroy can not be run for the workaround to work. The vhost file will then be created successfully and nginx will start serving files.

Here is the output from from vagrant debug containing all lines pertaining to /etc/nginx/sites- in the order they occured:

==> default: Debug: File[/etc/nginx/sites-enabled]: Adding default for owner
==> default: Debug: File[/etc/nginx/sites-enabled]: Adding default for group
==> default: Debug: File[/etc/nginx/sites-enabled]: Adding default for mode
==> default: Debug: File[/etc/nginx/sites-enabled/default]: Adding default for owner
==> default: Debug: File[/etc/nginx/sites-enabled/default]: Adding default for group
==> default: Debug: File[/etc/nginx/sites-enabled/default]: Adding default for mode
==> default: Debug: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/Concat[/etc/nginx/sites-available/host.dev.conf]/notify: subscribes to Class[Nginx::Service]
==> default: Debug: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/File[host.dev.conf symlink]/require: requires Concat[/etc/nginx/sites-available/host.dev.conf]
==> default: Debug: /Stage[main]/Nginx::Config/File[/etc/nginx/sites-available]: Autorequiring File[/etc/nginx]
==> default: Debug: /Stage[main]/Nginx::Config/File[/etc/nginx/sites-enabled]: Autorequiring File[/etc/nginx]
==> default: Debug: /Stage[main]/Nginx::Config/File[/etc/nginx/sites-enabled/default]: Autorequiring File[/etc/nginx/sites-enabled]
==> default: Debug: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/File[host.dev.conf symlink]: Autorequiring File[/etc/nginx/sites-enabled]
==> default: Debug: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/Concat[/etc/nginx/sites-available/host.dev.conf]/Concat_file[/etc/nginx/sites-available/host.dev.conf]: Autorequiring Concat_fragment[host.dev-header]
==> default: Debug: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/Concat[/etc/nginx/sites-available/host.dev.conf]/Concat_file[/etc/nginx/sites-available/host.dev.conf]: Autorequiring Concat_fragment[host.dev-footer]
==> default: Debug: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/Concat[/etc/nginx/sites-available/host.dev.conf]/Concat_file[/etc/nginx/sites-available/host.dev.conf]: Autorequiring Concat_fragment[host.dev-500-74b7cd5d5c91842e7fc8d2f68e055a5a]
==> default: Debug: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/Concat[/etc/nginx/sites-available/host.dev.conf]/Concat_file[/etc/nginx/sites-available/host.dev.conf]: Autorequiring Concat_fragment[host.dev-500-101cfb417e4733c93cc7ab4e574046cc]
==> default: Debug: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/Concat[/etc/nginx/sites-available/host.dev.conf]/Concat_file[/etc/nginx/sites-available/host.dev.conf]: Autorequiring Concat_fragment[host.dev-500-f6e92c3bc8575173fe1f8692b4b28cd5]
==> default: Debug: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/Concat[/etc/nginx/sites-available/host.dev.conf]/Concat_file[/etc/nginx/sites-available/host.dev.conf]: Autorequiring Concat_fragment[host.dev-500-6666cd76f96956469e7be39d750cc7d9]
==> default: Error: Could not set 'file' on ensure: No such file or directory - /etc/nginx/sites-available/host.dev.conf20160309-2597-1vw6pc5.lock
==> default: Error: Could not set 'file' on ensure: No such file or directory - /etc/nginx/sites-available/host.dev.conf20160309-2597-1vw6pc5.lock
==> default: No such file or directory - /etc/nginx/sites-available/host.dev.conf20160309-2597-1vw6pc5.lock
==> default: Error: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/Concat[/etc/nginx/sites-available/host.dev.conf]/File[/etc/nginx/sites-available/host.dev.conf]/ensure: change from absent to file failed: Could not set 'file' on ensure: No such file or directory - /etc/nginx/sites-available/host.dev.conf20160309-2597-1vw6pc5.lock
==> default: Notice: /Stage[main]/Nginx::Config/File[/etc/nginx/sites-enabled]/ensure: created
==> default: Debug: /Stage[main]/Nginx::Config/File[/etc/nginx/sites-enabled]: The container Class[Nginx::Config] will propagate my refresh event
==> default: Notice: /Stage[main]/Nginx/Nginx::Resource::Vhost[host.dev]/File[host.dev.conf symlink]: Dependency File[/etc/nginx/sites-available/host.dev.conf] has failures: true
==> default: Debug: /Stage[main]/Nginx::Config/File[/etc/nginx/sites-enabled/default]: Nothing to manage: no ensure and the resource doesn't exist
==> default: Notice: /Stage[main]/Nginx::Config/File[/etc/nginx/sites-available]/ensure: created
==> default: Debug: /Stage[main]/Nginx::Config/File[/etc/nginx/sites-available]: The container Class[Nginx::Config] will propagate my refresh event
==> default: Notice: /Stage[main]/Nginx::Service/Service[nginx]: Dependency File[/etc/nginx/sites-available/host.dev.conf] has failures: true
==> default: Notice: /Stage[main]/Nginx/Anchor[nginx::end]: Dependency File[/etc/nginx/sites-available/host.dev.conf] has failures: true

@marcgascon
Copy link

@3flex any news on this?

With @SamStonehouse solution mentioned it works, but then the file "/etc/nginx/mime.types" that nginx installs by default was removed and we don't know exactly why?

@nfourteen
Copy link

I looked into this error a little more today. Using the master branch:

In the manifests/resource/vhost.pp file the $config_file = ${vhost_dir}/${name_sanitized}.conf variable is defined and then created with concat. However, concat does not explicitly require the $vhost_dir (I think this is an implied dependency since the file is being created there, but I still get an error if it is not explicit). Also, on a side note, I'm wondering if concat should notify => Class['::nginx::service'] since the file is being created in the sites-available directory. Should the nginx service only be notified when a conf file is added to the sites-enabled directory to avoid unnecessary restarts? I'm not sure wether the following code should have the notify => Class['::nginx::service'] statement removed. I added require => File['$vhost_dir'], to explicitly require the directory.

concat { $config_file:
  owner   => $owner,
  group   => $group,
  mode    => $mode,
  notify  => Class['::nginx::service'],
  require => File['$vhost_dir'],
}

Another problem is when the $config_file symlink is created - it does not require the $vhost_enable_dir. For a fix, I updated the following require statement to include File[$vhost_enable_dir].

file{ "${name_sanitized}.conf symlink":
  ensure  => $vhost_symlink_ensure,
  path    => "${vhost_enable_dir}/${name_sanitized}.conf",
  target  => $config_file,
  require => [File[$vhost_enable_dir],Concat['$config_file']],
  notify  => Class['::nginx::service'],
}

If anyone else has some thoughts, please let me know. I will then submit a pull request.

@ryayon
Copy link

ryayon commented Apr 5, 2016

The problem still exists.
I will try to provide a fix.

vincenthuynh added a commit to vincenthuynh/challenge that referenced this issue May 17, 2016
@hostingnuggets
Copy link

I also have weird issues related to this such as:

(/Stage[main]/Nginx/Nginx::Resource::Upstream[phpfpm]/Concat[/etc/nginx/conf.d/phpfpm-upstream.conf]/File[/etc/nginx/conf.d/phpfpm-upstream.conf]/ensure) change from absent to file failed: Could not set 'file' on ensure: No such file or directory @ dir_s_rmdir - /etc/nginx/conf.d/phpfpm-upstream.conf20160601-6323-1aur8so.lock

Here it is trying to create an upstream file even before the /etc/nginx/conf.d directory exists, I guess before the package hast been installed...

Did anyone find a workaround? or when is this going to get fixed?

@brendanhill
Copy link

brendanhill commented Aug 16, 2016

I can confirm that the fix that @nfourteen suggests is the solution (baring the single quoted around the variables). The following errors are what I was experiencing:

Notice: /Stage[main]/Nginx::Package::Redhat/Yumrepo[nginx-release]/ensure: created
Info: changing mode of /etc/yum.repos.d/nginx-release.repo from 600 to 644
Notice: /Stage[main]/Nginx::Package::Redhat/Package[nginx]/ensure: created
Notice: /Stage[main]/Nginx::Config/File[/var/nginx]/ensure: created
Notice: /Stage[main]/Nginx::Config/File[/var/nginx/client_body_temp]/ensure: created
Error: Could not set 'file' on ensure: No such file or directory - /etc/nginx/sites-available/pseudo-domainname.com.conf20160816-14943-on1sji.lock
Error: Could not set 'file' on ensure: No such file or directory - /etc/nginx/sites-available/pseudo-domainname.com.conf20160816-14943-on1sji.lock
Wrapped exception:
No such file or directory - /etc/nginx/sites-available/pseudo-domainname.com.conf20160816-14943-on1sji.lock
Error: /Stage[main]/Nginx/Nginx::Resource::Vhost[pseudo-domainname.com]/Concat[/etc/nginx/sites-available/pseudo-domainname.com.conf]/File[/etc/nginx/sites-available/pseudo-domainname.com.conf]/ensure: change from absent to file failed: Could not set 'file' on ensure: No such file or directory - /etc/nginx/sites-available/pseudo-domainname.com.conf20160816-14943-on1sji.lock
Notice: /Stage[main]/Nginx::Config/File[/var/nginx/proxy_temp]/ensure: created

And my corrections are in manifests/resource/vhost.pp as:

concat { $config_file:
owner => $owner,
group => $group,
mode => $mode,
notify => Class['::nginx::service'],
require => File[$vhost_dir],
}

file{ "${name_sanitized}.conf symlink":
ensure => $vhost_symlink_ensure,
path => "${vhost_enable_dir}/${name_sanitized}.conf",
target => $config_file,
require => [File[$vhost_enable_dir],Concat[$config_file]],
notify => Class['::nginx::service'],
}

@terrarum
Copy link

I was having the same problem as @tgallant. If I ran vagrant up I got those errors and nginx would not work. If I then ran vagrant provision, everything would work.

I made the edits suggested by @nfourteen and everything works now on vagrant up.

juliacollins added a commit to nsidc/puppet-nginx that referenced this issue Sep 7, 2016
@wyardley
Copy link
Collaborator

wyardley commented Oct 8, 2016

I think #894 is similar? Does #906 address this, and is it a sane way to resolve the issue?
It seems similar to @juliacollins's solution.

It may cause minor problems if #878 gets merged, but we can burn that bridge when we come to it.

@wyardley
Copy link
Collaborator

I think the ordering should now be resolved with #906. If anyone is able to reproduce still, please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-feedback Further information is requested
Projects
None yet
Development

No branches or pull requests

10 participants