Archive multiple folders under a single folder using Ansible - ansible

I'm using the below ansible-playbook code to archive multiple folders under IBM folder.
Below is my absolute path Directory structure:
/app
|-- /IBM
|--/test
|--/log
|--/common
|--/api
|--/<unknown folders>
The number of folders and files under IBM folder is unknown hence it seems impossible to specify all the files / folders under IBM under exclude_path attribute.
I wish to build an archive (gz) that has only IBM folder containing only two folders i.e common and api folders while ignoring the rest of the folders and files.
Thus, I wrote the below playbook:
- name: Creating the archive
archive:
path:
- /was/IBM/common
- /was/IBM/api
dest: /var/backup/mysetup.tar.gz
exclude_path:
- /was/IBM/common/log
- /was/IBM/api/tmp
format: gz
This gives me the archive file mysetup.tar.gz.
I want the mysetup.tar.gz file to have a folder called IBM which should have the two folders common and api. Thus, I'm expecting the below in the mysetup.tar.gz no matter what other files are under the IBM folder.
IBM
|--/common
|--/api
But, the mysetup.tar.gz does not have IBM folder but has common and api folders.
I was not specific hence my question did not get answered here: How to archive multiple folders under one folder using Ansible
Can you please guide me as to how I can get the archive to have both the folders inside the IBM folder inside the mysetup.tar.gz?

Requirement you have can't be achieved straight using archive module. Two specific reasons are listed below:
If you specify the path say /app/IBM then the content of the zip file will have the path after IBM something like common/, api/. To get IBM as a root directory inside the tar.gz file, you need to specify path as /app. This brings to the next point about the usage of exclude_path.
exclude_path doesn't work as you would expect. Say, if the path is define as /app and you want to exclude /app/IBM/test, this wouldn't work. exclude_path works only with direct sub folder/file of a defined path (with wildcard) which means that exclusion of /app/IBM/test would work if path defined as /app/IBM/* but that is not what is expected and brings back the previous point. There is already an issue reported on this topic.
So you probably better off using regular tar command using command/shell module.

Related

Python library files are not inside folders when deployed to AWS Lambda

The first screenshot is from a lambda in the AWS console. Why all the files are NOT in its own folders? The screenshot is attached. These filers are from python libraries, somehow the files are out of folders.
The second screenshot is how the folders I am expecting. When I unzip the zip file which got developed to AWS, it looks like the second screenshot.
It should show like this in the AWS Lambda console:
You most likely used Windows's Compress-archive or something similar to create the zip file for the lambdas. Since the file separator in Windows and Linux are different, the lambda does not recognize the folder structure correctly, and instead it treats them as long file names.
Try to use, for instance 7-Zip, for zipping the files when you are on Windows. That should fix the file separator issue, since 7-zip uses the cross compatible / as the file separator instead of Windows specific \.

apache nifi recursively fetch files from web server directory

I have web server with autoindex module that lists all files and folders. Something like that:
How can i recursively fetch all files using Apache NiFi? I tried to use ListFTP/FetchFTP processors, but without any luck.
Can someone tell me what processors should i use for this task?
As remote path you should specify the root folder from which you want to List/Fetch all files and sub folders.
In your case, you put /FILE/store/0002550267/ as remote path, so only files and folders in this directory will be picked up.
Change remote path to /File (or / if you want all files on the server) and you should see all files being listed.

How to reference other files within a lambda function?

In a handler of mine, I open a .mmdb file for doing geo lookups. In my package, I use ./ notation to reference the file since the handler and file are in the same directory. Now that I want to deploy the function using serverless, I've included the file within the include block in my serverless.yml file. Based on the package size that I'm seeing, the file is being uploaded, however I'm getting the error
open ./GeoLite2-City.mmdb: no such file or directory
when running the lambda. What is the proper way to get the location of the file from within my lambda?
I solved my problem by listing the contents of the directory that I was using in my lambda, using the code found in this answer: List directory in Go. After doing so I realized that I was in the root directory of the entire folder that I uploaded, not the directory of the specific package I was running the code from (containing main.go)

What is a usual workflow for dealing with shared files with capistrano?

My .csv recreates on every release, and, as I understand, to keep its data unchanged between deploys I need to put it in /shared directory and simlink to it from my deploy.rb.
Is this the right route? (I have this question because I don't seem to find much info on how to do this with respect to, eg, databases, for some reason. /shared directory is mostly used for .conf files and paperclip-like directories).
When using capistrano, your application code will be "uploaded" to some directory on the server. Capistrano uses this structure:
/path_to_folder:
current - symlink to the directory with the current release
releases - contains all kept releases
shared - files that should persist between releases
So to your question - copy the .csv file somewhere into "shared" directory and then in the config/deploy.rb add this:
namespace :deploy do
task :create_symlinks do
run "ln -s #{shared_path}/something.csv #{latest_release}/db/something.csv"
end
end
after 'deploy:update_code', 'deploy:create_symlinks'
Replace "something" with the file name that you copied. You can also put the csv file into some directory under "shared" if you want to, I'd use "db" in this case. If you do so, don't forget to update path in the symlink.

How to change Controllers/Models source directory in CodeIgniter

I need to load controllers and models from a different folder than the default one. I am using a Linux system.
I am building a simple CI application for some people, for use on a shared hosting I own. But I want to give them access only to /views folder and some /config files. And this is why I need to store the controllers and models in a different folder on the same level as /public_html folder or maybe somewhere in the linux system.
I consider this would be a better solution than encoding files
CodeIgniter permits you to organize your controllers,views and config files into sub-folders. As far as I know it doesn't permit it for models (at least documentation doesn't mention it, I've not tried myself).
As your are in a Linux system, you can create a symbolic link to reference to another directory in the filesystem.
So you can create the directories:
application/config/public
application/controllers/public
application/views/public
And then create in your /public_html symbolic links ponting to these directories:
/public_html/config -> application/config/public
/public_html/controllers -> application/controllers/public
/public_html/views ->application/views/public
When your customers upload files to /public_html/config, they will be also available in application/config/public. The same applies for /public_html/controllers and /public_html/views.
The command syntaxis to creates symlinks is
# ln -s target name
i.e:
# ln -s application/config/public /public_html/config
If you don't have console access to your hosting you can create the links using the PHP function symlink() .
To load a view/config/controller from a subfolder you only have tu prepend the directory name in the $this->load->...() function call. i.e:
$this->load->view('public/my_view);
Check CI documentation for more info about organizing your files into sub-folders.

Resources