Vagrant edit owner of folder throws syntax error - laravel

Hi I am trying to edit the owner of a laravel directory that I have, I am doing this via the config file for vagrant as below:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :private_network, ip: "192.168.33.21"
config.vm.provision :shell, :path => "install.sh"
config.vm.synced_folder ".", "/var/www”
config.vm.share_folder "v-root", "/tempus2/app/storage", ".", :owner => "www-data"
end
however I get the following error:
Users/guti/Public/Sites/Vagrantfile:13: syntax error, unexpected tIDENTIFIER, expecting
keyword_end
config.vm.share_folder "v-root", "/tempus2/app/storage...
^
/Users/guti/Public/Sites/Vagrantfile:13: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
...config.vm.share_folder "v-root", "/tempus2/app/storage", "."...
... ^
/Users/guti/Public/Sites/Vagrantfile:13: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
...v-root", "/tempus2/app/storage", ".", :owner => "www-data"
... ^
/Users/guti/Public/Sites/Vagrantfile:13: syntax error, unexpected tSTRING_BEG, expecting '('
...t", "/tempus2/app/storage", ".", :owner => "www-data"
... ^
/Users/guti/Public/Sites/Vagrantfile:13: syntax error, unexpected tIDENTIFIER, expecting keyword_end
...p/storage", ".", :owner => "www-data"
... ^
/Users/guti/Public/Sites/Vagrantfile:13: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
/Users/guti/Public/Sites/Vagrantfile:13: unterminated string meets end of file
What is the correct syntax for www-data? also how can I extend the config file to change the permissions for this folder and all subdirectories to 777?
All i want to do is make the tempus2/app/storage directory writeable by www-data for laravel purposes. THe full directory on my machince is User/[username]/Public/Sites/tempus2/ and my vm is /var/www/tempus2 or when i ssh into vagrant cd /vagrant/tempus2. but how can i change the permissions on this folder for my vagrant vm?

share_folder isn't available in Vagrant 1.1+ (that's the old syntax), its now synced_folder. Also it looks like your double quote on the "/var/www" line is not actually a double quote character, probably copy and pasted from somewhere.

Related

Chef template variables syntax error, unexpected '}', expecting keyword_end

For my following recipe:
template '/etc/filebeat/filebeat.yml' do
source 'filebeat.yml.erb'
owner 'root'
group 'root'
mode '0600'
variables(
stack_name: stack_name,
instance_ip: instance_ip
)
end
I am getting following error:
Chef::Mixin::Template::TemplateError
------------------------------------
(erubis):74: syntax error, unexpected '}', expecting keyword_end
Resource Declaration:
---------------------
# In /var/chef/runs/8f9aa33c-6b69-419d-8a02-5668701a228a/local-mode-cache/cache/cookbooks/filebeat/recipes/filebeat.rb
28: template '/etc/filebeat/filebeat.yml' do
29: source 'filebeat.yml.erb'
30: owner 'root'
31: group 'root'
32: mode '0600'
33: variables(
34: stack_name: stack_name,
35: instance_ip: instance_ip
36: )
37: end
38:
Compiled Resource:
------------------
# Declared in /var/chef/runs/44a77122-2816-4f89-97c4-9cbff0bbdfcb/local-mode-cache/cache/cookbooks/-filebeat/recipes/filebeat.rb:28:in `from_file'
template("/etc/filebeat/filebeat.yml") do
action [:create]
retries 0
retry_delay 2
default_guard_interpreter :default
source "filebeat.yml.erb"
variables {:stack_name=>"fsdfsd", :instance_ip=>"172.31.63.242"}
declared_type :template
cookbook_name "filebeat"
recipe_name "filebeat"
owner "root"
group "root"
mode "0600"
path "/etc/filebeat/filebeat.yml"
end
What am I doing wrong?
I think the error is in your template file, e.g. filebeat.yml.erb
The reason for my assumption is based on (erubis):74: syntax error, unexpected '}', expecting keyword_end - erubis is a fast eRuby-compatible template engine ("erb") used by chef. So the error origins from parsing/rendering the template file, not a chef specific issue.

How to write to a file provisioning from Vagrantfile

Hi I'm trying to add a Directory Index directive to the default VirtualHost for Apache from the Vagrantfile. I'm wondering if there is a way to edit a file from the Vagrantfile (I'm usung inline SHELL). I know I could copy an entire VH file to the guest machine, but I want to know how to write into files if possible.
Thanks!
You can do that with ansible like this:
config.vm.provision "ansible_local" do |ansible|
ansible.verbose = "vv"
ansible.become = true # execute as root
ansible.playbook = "relative_path_to_ansible_file/playbook.yml"
end
or with a shell
Vagrant.configure("2") do |config|
config.vm.provision "shell" do |s|
s.inline = "echo $1"
s.args = "'hello, world!'"
end
end
https://www.vagrantup.com/docs/provisioning/shell.html

use Chef file.insert_line_if_no_match method for CIDR address

I am trying to use file.insert_line_if_no_match for CIDR address:
attributes/default.rb:
default["chefclustercidr"]["ip"] = "a.b.c.d/24"
recipe/default.rb
ruby_block "chef-backend.rb" do
block do
file = Chef::Util::FileEdit.new("/etc/chef-backend/chef-backend.rb")
file.insert_line_if_no_match("/publish_address/" , "publish_address i#{node['chefclusterbe1']['ip']}")
file.insert_line_if_no_match("/postgresql/" , "postgresql.md5_auth_cidr_addresses = ["samehost", "samenet", "#{node['chefclustercidr']['ip']}/24"]")
file.write_file
end
end
but getting ruby syntax error
$ruby -c default.rb
default.rb:95: syntax error, unexpected tIDENTIFIER, expecting ')'
th_cidr_addresses = ["samehost", "samenet","#{node['chefclus
^
default.rb:95: syntax error, unexpected tIDENTIFIER, expecting keyword_end
resses = ["samehost", "samenet","#{node['chefclustercidr']['
^
default.rb:99: syntax error, unexpected keyword_end, expecting end-of-input
FileEdit is an internal class and using it from recipe code is NOT SUPPORTED. Do not use it. Period.
That said, the problem is you have unescaped double quotes in your string.
Instead of insert_line_if_no_match you can deal with it another way, using bash and grep. I have added the way to another question you can have a look here
here is the bash resource i usually use to append to files only if there is no match:
bash 'append line(s) to file if it doesnt exist' do
user 'user'
code <<-EOS
cat >>/home/file <<EOL
*.* ##172.167.189.67:514
EOL
EOS
not_if "grep -q 172.167.189.67 /home/file"
end
you may need to run cookstyle on that ^

Issue with vagrant while using vagrant up

on installing fresh vagrant instance, I am getting this error while using vagrant up. Here is the error
Vagrant failed to initialize at a very early stage:
There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience:
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:141: syntax error, unexpected tPOW
...ype: folder["type"] ||= nil, **options
... ^
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:157: syntax error, unexpected keyword_do_block, expecting keyword_end
settings["sites"].each do |site|
^
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:207: syntax error, unexpected keyword_do_block, expecting keyword_end
settings["databases"].each do |db|
^
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:208: syntax error, unexpected tSTRING_BEG, expecting keyword_end
config.vm.provision "shell" do |s|
^
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:208: syntax error, unexpected keyword_do_block, expecting keyword_end
config.vm.provision "shell" do |s|
^
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:220: syntax error, unexpected keyword_end, expecting $end
Here is my VagrantFile content
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'json'
require 'yaml'
VAGRANTFILE_API_VERSION ||= "2"
confDir = $confDir ||= File.expand_path("~/.homestead")
homesteadYamlPath = confDir + "/Homestead.yaml"
homesteadJsonPath = confDir + "/Homestead.json"
afterScriptPath = confDir + "/after.sh"
aliasesPath = confDir + "/aliases"
require File.expand_path(File.dirname(__FILE__) + '/scripts/homestead.rb')
Vagrant.require_version '>= 1.8.4'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if File.exist? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases"
end
if File.exist? homesteadYamlPath then
settings = YAML::load(File.read(homesteadYamlPath))
elsif File.exist? homesteadJsonPath then
settings = JSON.parse(File.read(homesteadJsonPath))
end
Homestead.configure(config, settings)
if File.exist? afterScriptPath then
config.vm.provision "shell", path: afterScriptPath, privileged: false
end
if defined? VagrantPlugins::HostsUpdater
config.hostsupdater.aliases = settings['sites'].map { |site| site['map'] }
end
end
============================================================
And there is the YAML file
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Code
to: /mnt/e/XAMPP/htdocs
sites:
- map: homestead.app
to: /mnt/e/XAMPP/htdocs/cap/web
databases:
- homestead
Solved that issue by upgrading Vagrant to 1.8.4.

Ruby unexpected ':', expecting kEND

I want to set up vagrant on my Ubuntu, when "vagrant up", it always give me the following error
syntax error, unexpected ':', expecting kEND
config.vm.provision :shell, path: "vagrantprov.sh"
I checked the Vagrantfile, it should be OK, can anyone tell me where the error is? Thanks.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
end
config.vm.provision :shell, path: "vagrantprov.sh"
end
Ruby <1.9? Old fashioned hash syntax style is required for old Ruby version
config.vm.provision :shell, :path => "vagrantprov.sh"
What version of Ruby are you running? The named args syntax (path: "...") is supported from on 1.9 and above, perhaps you have a lower Ruby version?
(1.8)
1.8.7 :001 > puts "a", b: 1
SyntaxError: compile error
(irb):1: syntax error, unexpected ':', expecting $end
(1.9)
1.9.3p429 :001 > puts "a", b: 1
a
{:b=>1}
=> nil
Ruby < 1.9 :
:a => 1
Ruby >= 1.9 :
a : 1

Resources