How would write ansible script to find if directory is mounted or not? - directory

I need to check if a directory is mounted or not. I have checked on doc.ansible for help but they only have create or delete.
I am using visual code for ansible and vm for directory file.

Module setup returns a list of mounted filesystems "ansible_mounts". It is possible to test it
ansible remote-host -m setup

Related

deploy project to remote server with rsync command

I'm using rsync command to deploy symfony 4 project to remote server, every time when I make new change the command deploy all the project's file instead of new files !! which option to add to tell rsync that should only transfer new changes!
I'm using rsync like that :
rsync -av LocalProjectPath RemotePerverPath --include=public/.htaccess --include=public/build --include=vendor --exclude=".*"
I can refer you to this page for detailed information:
https://www.tecmint.com/sync-new-changed-modified-files-rsync-linux/
rsync has built-in parameters for those purposes
"--ignore-existing" allows you to transfer only new files.
"--update --dry-run" allows you to transfer only updated and modified files.

Corda plugins and base-directory configuration

I've setup a 4 node corda network with Notary, NodeA, NodeB and NodeC. When I bring up node and webserver instances for individual nodes, network comes up healthy. But,
1) I want to keep the configs under /etc/node.conf and runtime environment under /opt/corda directories for each of the nodes. When I provide --config-file and --base-directory arguments, per documentation, corda refuses to run with both arguments as inputs. Is there a way to isolate runtime environments and configs?
2) How do I make the nodes pick up the jars under plugins ? I've created a plugins directory for each of these nodes under basedirectory path - /opt/corda/plugins. But, created it's own plugins directory. (Albeit, in my current setup I have a node.conf file under /opt/corda/ to keep it going). Where must I deploy my cordapps if corda is not picking up from the plugins folder I've created? Am I missing something here ? I've followed the docs during my setup.
1) As you observed, using the --config-file and --base-directory command line arguments together is currently disallowed.
However, you can store your node.conf file in a separate location by creating a symlink in the root of the node folder that points to the actual location of the node.conf file (e.g. ln -s ./conf/node.conf ./node.conf on Mac if you are storing the node.conf file in a conf folder in the node's root directory).
2) Awaiting clarification.

sftp uploading to non-existing directory

Say I have to upload file dir-a/dir-b/dir-c/xxx.txt using sftp
Should I create the target directory first?
Should I open target directory before copying the file?
If have to create this path dir-a/dir-b/dir-c - is it one command or three?
Should I create the target directory first?
Usually yes. SFTP servers usually do not create parent directory. But how hard is it to try first?
Should I open target directory before copying the file?
You do not have to. put command does accept a remote-path, which can be either absolute or relative to remote working directory.
If have to create this path dir-a/dir-b/dir-c - is it one command or three?
These are three commands:
mkdir dir-a/
mkdir dir-a/dir-b/
mkdir dir-a/dir-b/dir-c

AWS beanstalk wordpress

I was trying to setting up my AWS beanstalk by following the implementation guide provided by AWS.
But when I got to the "Launch an Elastic Beanstalk Environment" section, this message appeared which basically said the app is not created.
Here's the message:
[Instance: i-088472611e1ef4405] Command failed on instance. Return
code: 1 Output: ln: failed to create symbolic link
'wp-content/uploads': No such file or directory. container_command
2link in wordpress-beanstalk/.ebextensions/efs-mount.config failed.
For more detail, check /var/log/eb-activity.log using console or EB
CLI.
Does anyone have the same problem or know how to resolve this?
Try changing the efs-mount to read the following, the directory clearly doesn't exist so lets just create it.
container_commands:
1chown:
command: "chown webapp:webapp /wpfiles"
2create:
command: "sudo -u webapp mkdir -p wp-content/uploads"
3link:
command: "sudo -u webapp ln -s /wpfiles wp-content/uploads"
2create will create the directory owned by the webapp user and should let you continue.
I just faced the same issue. I am going to assume deploying via the AWS console. That is how I started.
STEP 1: I checked if there was an actual directory wp-content/uploads in wordpress-beanstalk and there was not. It might get created on the first WP upload So, I created the folder, rezipped the application, and deployed to Beanstalk via the AWS Console.
I still received the same error and moved on to step 2
STEP 2: Run EB DEPLOY from the command line
from my local wordpress-beanstalk directory
eb init
choose region (if you already created your app should be this region)
if you already created application choose that wordpress-beanstalk for example
eb use name of your environment
eb deploy
I am not certain that Step 1 is related to Step 2, but was able to successfully deploy facing the same issue using EB CLI.
This is the mounting error of EFS .
EB is using EFS storage to store the wordpress files .
Please check the no.7 in documentation .
"Modify the configuration files in the .ebextensions folder with the IDs of your default VPC and subnets, and your public IP address."
Please edit the efs-create.config file inside the .ebextension folder.
A bit late here so for anyone else having this issue, it's caused when that directory does not exist. Here are some reasons this might happen:
1). WP has not created it - Check manually that it exists.
2). .gitignore - When a .ebignore file is not present, EB uses your .gitignore instead. This can cause the directory to not be uploaded with the EB deploy command. If this is the case, make a .ebignore, EB will start ignoring the .gitignore
3). Document root - If you have modified the document root, to something like /src you have to modify the efs-mount.config file.
##############################################
#### Do not modify values below this line ####
##############################################
container_commands:
1chown:
command: "chown webapp:webapp /wpfiles"
2link:
command: "sudo -u webapp ln -s /wpfiles src/wp-content/uploads"
Even though the file mentions not to modify it, you have to add your document root path in the 2link entry. Change wp-content/uploads to src/wp-content/uploads (replace src with your document root)
Finally, I would not include a command to automatically make this directory, as that only puts a band-aid on the problem.
Hope this helps

Passing environment variables through jar file which app uses

I am currently trying out on the docker link between my app and db containers. I've checked on my app container and environment variables are automatically set when I link the containers together.
What I want to do is for my config file, which is packaged into a jar file, to receive the environment variables and set the required values to it. Any advice or help?
And this is how I create a config file in my jar file to connect to MySQL
database { url="jdbc:mysql://${MYSQL_PORT_3306_TCP_ADDR}:${MYSQL_PORT_3306_TCP_PORT}/mydb" driver="com.mysql.jdbc.Driver"}
Updating the config file inside the jar could be quite overkill.
It think you have several choices
read the config environment variable directly in you program
use variable either directly or generate the config file there
create launch script (details of this depends of you guest os in docker how to do it; sh/bash for linux etc..)
that script can generate new config file from environment and put it on classpath before jar so you program sees it.
EDIT: added example
You can save this kind of launcher script on docker image which dynamically creates configuration before launching actual program.
#!/bin/bash
# some default values for testing even without links to other container
MYSQL_PORT_3306_TCP_ADDR=${MYSQL_PORT_3306_TCP_ADDR:-127.0.0.1}
MYSQL_PORT_3306_TCP_PORT=${MYSQL_PORT_3306_TCP_PORT:-3306}
cat << EOF > /opt/yourprogram/dbconfig.conf
database { url="jdbc:mysql://${MYSQL_PORT_3306_TCP_ADDR}:${MYSQL_PORT_3306_TCP_PORT}/mydb" driver="com.mysql.jdbc.Driver"
}
EOF
scala -classpath /opt/yourprogram YourProgram
What I did is that I wrote the sh file in my directory /tmp/restcore-1.0-SNAPSHOT/bin like this:
#!/bin/bash echo "database{url="jdbc:mysql://"${MYSQL_PORT_3306_TCP_ADDR}":"${MYSQL_PORT_3306_TCP_PORT}"/mydb" driver="com.mysql.jdbc.Driver" }" > myconf.conf
jar uf /tmp/restcore-SNAPSHOT/lib/com.organization.restcore-1.0-SNAPSHOT.jar /tmp/restcore-1.0-SNAPSHOT/bin/myconf.conf
After building the Dockerfile and running the sh file in CMD, I use cat myconf.conf to check the config file and I'll be able to see the environment set.

Resources