Capistrano floating literal anymore; put 0 before dot (SyntaxError) - capistrano

I have a little bit of experience using Capistrano but only on projects that are already using it and I am currently trying to set it up on a new project. I have created my config/deploy.rb file, added the appropriate configuration and am now trying to run "cap deploy:setup" to set the correct capistrano structure up on my remote server however now when I try to run this or any other Capistrano commands I get:
/Library/Ruby/Gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/loading.rb:93:in `instance_eval': ./config/deploy.rb:8: no . floating literal anymore; put 0 before dot (SyntaxError)
role :web, xxx.x.xx.xx
It looks like an issue with the format of the IP that I have provided for my app but no variations seem to work.
Am I missing something obvious here?
Has anyone else come across this issue?
Thanks
James

I found a resolution for this in the end through trial and error. It turns out that I needed to wrap the role :web and role :app values in quotes:
"xx.xx.xx.xx"
Then it worked correctly.

Related

Error in Google Cloud Shell Commands while working on the lab (Securing Google Cloud with CFT Scorecard)

I am working in a GCP lab (Securing Google Cloud with CFT Scorecard). All instructions for the lab are given.
First I have to run the following two commands to set environment variables
export GOOGLE_PROJECT=$DEVSHELL_PROJECT_ID
export CAI_BUCKET_NAME=cai-$GOOGLE_PROJECT
In the second command given above I don't know what to replace with my own credentials? May be that is the reason I am getting error.
Now I have to enable the "cloudasset.googleapis.com" gcloud service. For this they gave the following command.
gcloud services enable cloudasset.googleapis.com \
--project $GOOGLE_PROJECT
Error for this is given in the screeshot attached herewith:
Error in the serviec enabling command
Next step is to clone the policy: The given command for that is:
git clone https://github.com/forseti-security/policy-library.git
After that they said: "You realize Policy Library enforces policies that are located in the policy-library/policies/constraints folder, in which case you can copy a sample policy from the samples directory into the constraints directory".
and gave this command:
cp policy-library/samples/storage_blacklist_public.yaml policy-library/policies/constraints/
On running this command I received this:
error on running the directory command
Finally they said "Create the bucket that will hold the data that Cloud Asset Inventory (CAI) will export" and gave the following command:
gsutil mb -l us-central1 -p $GOOGLE_PROJECT gs://$CAI_BUCKET_NAME
I am confused in where to replace my own credentials like in the place of project_Id I wrote my own project id.
Also I don't know these errors are ocurring. Kindly help me.
I'm unable to access the tutorial.
What happens if you run the following:
echo ${DEVSHELL_PROJECT_ID}
I suspect you'll get an empty result because I think this environment variable isn't actually set.
I think it should be:
echo ${DEVSHELL_GCLOUD_CONFIG}
Does that return a result?
If so, perhaps try using that variable instead:
export GOOGLE_PROJECT=${DEVSHELL_GCLOUD_CONFIG}
export CAI_BUCKET_NAME=cai-${GOOGLE_PROJECT}
It's not entirely clear to me why this tutorial is using this approach but, if the above works, it may get you further along.
We're you asked to create a Google Cloud Platform project?
As per the shared error, this seems to be because your env variable GOOGLE_PROJECT is not set. You can verify it by using echo $GOOGLE_PROJECT and seeing whether it returns the project ID or not. You could also use echo $DEVSHELL_PROJECT_ID. If that returns the project ID and the former doesn't, it means that you didn't export the variable as stated at the beginning.
If the problem is that GOOGLE_PROJECT doesn't have any value, there are different approaches on how to solve it.
Set the env variable as you explained at the beginning. Obviously this will only work if the variable DEVSHELL_PROJECT_ID is also set.
export GOOGLE_PROJECT=$DEVSHELL_PROJECT_ID
Manually set the project ID into that variable. This is far from ideal because in Qwiklabs they create a new temporal project on every lab, so this would've only worked if you were still on that project. The project ID can be seen on both of your shared screenshots.
export GOOGLE_PROJECT=qwiklabs-gcp-03-c6e1787dc09e
Avoid using the argument --project. According to the documentation, the aforementioned argument is optional and if none is used the command will take the one by default, which will be on the configuration settings. You can get the current project by using this:
gcloud config get-value project
If the previous command matches the project ID you want to use, you can simply issue the following command:
gcloud services enable cloudasset.googleapis.com
Notice that the project ID is not being explicitly mentioned using --project.
Regarding your issue with the GitHub file, I have checked the repository and the file storage_blacklist_public.yaml doesn't seem to be in the directory policy-library/samples. There seems to be a trace that it was once there, but it isn't anymore, they should probably update the lab as it isn't anymore.
About your credentials confusion, you don't have to use your own project ID, just the one given on your lab. If I recall properly all the needed data should be on the left side of the lab. Still, you shouldn't need to authenticate in a normal situation as you are already logged in your temporal project if you are accessing it form the Cloud Shell, which is where you should be doing all this.
Adding this for the later versions
in the gcloud shell you can set a temp variable for the current project id with
PROJECT_ID="$(gcloud config get-value project)"
then use like
--project ${PROJECT_ID}

Wildfly CLI - disable environment variable resolution? i.e. write unresolved variable to config

I'm trying to modify the config of a running Wildfly (inside Docker) using the JBoss CLI. One thing I need to do is
data-source add --connection-url=jdbc:mysql://${DB_PORT_3306_TCP_ADDR}:3306/xplore (...)
I need the resulting config in standalone.xml to literally contain
<connection-url>jdbc:mysql://${DB_PORT_3306_TCP_ADDR}:3306/xplore</connection-url>
DB_PORT_3306_TCP_ADDR is a variable that will be resolved by Wildfly when it's rebooted. It does not exist when I'm CLI-ing.
The problem is that CLI attempts to resolve it (and fails) during my CLI session (instead of injecting it as a plain string), resulting in output like errors and even
<connection-url>$</connection-url>
I've tried to work around this by adding "..." and '...', escaping the $ to \$, removing the brackets, and defining a variable containing my string in the script and inserting that variable (still gets resolved). I've looked up the docs on this, and while there is a command resolve-expression(), there is no inverse, no setting for it, nothing. It doesn't seem possible to prevent the resolution from happening.
How can I insert an unresolved expression into my config via the CLI?
The answer was to issue this command:
data-source add --connection-url=jdbc:mysql://${DB_PORT_3306_TCP_ADDR:}:3306/xplore (...)
With a : after ADDR. This obviously solves the resolution error since it will now default to an empty value, and somehow it actually causes the string value itself to be written. It also turns out it wasn't the CLI that was resolving my variable, but the server itself.
The real solution though was to stop the session, modify the server settings and disable variable resolution entirely, then start a new session.

HOCON not substituting environment variables

I have read the documentation concerning falling back to environment variables at https://github.com/typesafehub/config/blob/master/HOCON.md#substitution-fallback-to-environment-variables. My understanding was that it would pickup any envars. So for instance, if from the shell I was able to do echo $HOSTNAME and see a non-empty response then HOCON should do that as well.
In my application.conf I have a line
akka.remote.netty.tcp.hostname = ${HOSTNAME}
However, my app is not happy with this and fails to start with.
/conf/application.conf: 9: Could not resolve substitution to a value: ${HOSTNAME}
Is this a user issue? A shell issue? I am able to login as the user and echo $HOSTNAME
Tagging this scala and akka since that userbase probably has the most exposure to HOCON
The reason for HOCON not picking up the envar is that my app runs as a linux service (Centos 6.5) which clears away most environment variables.
See https://unix.stackexchange.com/questions/44370/how-to-make-unix-service-see-environment-variables for a relevant description of the issue
this is a shot in the dark, but are you using an older version of typesafe-config? maybe its a newer-ish feature? the feature seems to be advertised as you describe, but if you are pulling in typesafe-config as a transient dependency (say from akka), maybe you are getting an older version.
what happens if you remove the substitution in your .conf file (so parsing is successful) and then print out the contents of ConfigFactory.systemEnvironment()? for reference: http://typesafehub.github.io/config/latest/api/com/typesafe/config/ConfigFactory.html#systemEnvironment--
HOSTNAME isn't an environment variable. It's a bash internal variable. See https://superuser.com/questions/132489/hostname-environment-variable-on-linux for more details.

Capistrano deploy how to use use_sudo and admin_runner

I'm trying to configure Capistrano so that it works for our server setup. We are deploying symfony projects so i'm also using capifony. I'm still experiencing some problems with permissions.
On our server every project runs as a project user, so every project has it's own user. So i configured use_sudo and set it to true and i configured the admin_runner to be the user of the project. But it still didn't work so i modified the capifony to start using try_sudo in stead of the regular run. Which made it work a little bit better. But i'm a bit confused about what to use in which case. You have try_sudo, sudo and run. But which is needed for which use-case?
When you use run i think it'll always be your local user
try_sudo i think will check if the use_sudo flag is true if so it will use the sudo command if not it will use the local user. If you have admin_runner configured it will sudo to the user configured as admin_runner
sudo will always try to sudo
Now my problem is the deploy:symlink method this is also just a regular run command so it executes as the local user, which gives permission problems when i try to view the website.
So can anyone tell me if my description of the 3 commands is correct? and also does anyone know how the admin_runner and use_sudo is suposed to be used, so that the symlink is also being done correctly (and also all other commands done by capistrano)?
kind regards,
Daan
Apologies for such a tardy answer Daan. Your understanding of Capistrano is correct. Note also that the :use_sudo flag defaults to true.
In Capistrano 2.11.2, you'll find lib/capistrano/configuration/variables.rb:
_cset(:run_method) { fetch(:use_sudo, true) ? :sudo : :run }
and lib/capistrano/recipes/deploy.rb:
def try_sudo(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
command = args.shift
raise ArgumentError, "too many arguments" if args.any?
as = options.fetch(:as, fetch(:admin_runner, nil))
via = fetch(:run_method, :sudo)
if command
invoke_command(command, :via => via, :as => as)
elsif via == :sudo
sudo(:as => as)
else
""
end
end
Perhaps your permissions problem involves your server, running as a normal user, not being able to read the contents of the release directory that your current symlink is pointing to?

when I add "<Runtime executionContext="elevated" />" to my web role definition, and attempt to deploy, it fails to start

When I add "" to my ServiceDefinition.csdef, it fails to start when publishing:
<WebRole name="xxx" vmsize="Small" enableNativeCodeExecution="true">
<Runtime executionContext="elevated" />
<Sites>...
Everything works with it gone. Need to add it to specify machine key in Azure SDK 1.3, as described here: http://msdn.microsoft.com/en-us/library/gg494983.aspx
Anyone else run into this?
Would running under admin privileges cause other code to break? When I RDP in, the error I find when I run on localhost is not related to this, but it's code that works when this runtime line is removed.
I just checked the Service Definition Schema and the Runtime
element does not exist inside WebRole.
Actually it does.
<WebRole name="<web-role-name>" vmsize="[ExtraSmall|Small|Medium|Large|ExtraLarge]" enableNativeCodeExecution="[true|false]">
...
<Runtime executionContext="[limited|elevated]">
I just checked the Service Definition Schema and the Runtime element does not exist inside WebRole.
If you would like to have Full Trust, you should go to yor CloudService project properties and set it there. But i really don't know if you need that to specify the machine key.
Best regards