Using supervisord, I am unable to use a file path with a space in one of the directories. I am trying to use my iCloud Drive folder as the path to the file.
the path:
~/Library/Mobile Documents/com~apple~CloudDocs/Code/modbot/modbot.py
my program supervisord.conf (non working. works when pointed to a new path without a space in the directory)
[program:modbot]
command=/Users/Jonathan/.virtualenvs/modbot/bin/python3.7 /Users/Jonathan/code/modbot/modbot.py
paths I've tired in supervisord.conf:
~/Library/Mobile Documents/com~apple~CloudDocs/Code/modbot/modbot.py
~/Library/Mobile\ Documents/com~apple~CloudDocs/Code/modbot/modbot.py
~/Library/Mobile' 'Documents/com~apple~CloudDocs/Code/modbot/modbot.py
"~/Library/Mobile Documents/com~apple~CloudDocs/Code/modbot/modbot.py"
~/Library/"Mobile Documents"/com~apple~CloudDocs/Code/modbot/modbot.py
After googling I even tried double escaping but nothing is working.
turns out I'm an idiot. supervisord doesn't use ~ so that was the problem, working code:
[program:modbot]
command=/Users/Jonathan/.virtualenvs/modbot/bin/python3.7 "/Users/Jonathan/Library/Mobile Documents/com~apple~CloudDocs/Code/modbot/modbot.py"
I'm trying to do vagrant up inside the following directory:
~/Desktop/Apps & Co./company/My App/Backend/
I know, I should fix my naming conventions. Can't help it right now, though.
As you can see, there are several special characters in the path, such as (space), &, and ..
The Homestead.yaml file contains this:
folders:
-
map: ~/Desktop/Apps & Co./company/My App/Backend/
to: /home/vagrant/app
When running vagrant up from inside that directory, I'm seeing the following (abbreviated) error:
There was an error loading a Vagrantfile.
Message: LoadError: cannot load such file -- /Users/linusgeffarth/Desktop/Apps & Co./company/My App/Backend/vendor/laravel/homestead/scripts/homestead.rb
Yes, Vagrantfile exists in this directory. I copied the path into terminal to verify.
I tried the following paths in Homestead.yaml:
map: ~/Desktop/Apps & Co./company/My App/Backend/
map: ~/Desktop/Apps&Co./company/MyApp/Backend/
map: ~/Desktop/AppsCo/company/MyApp/Backend/
map: ~/Desktop/Apps\ \&\ Co./company/My\ App/Backend/
map: '~/Desktop/Apps & Co./company/My App/Backend/'
map: "~/Desktop/Apps & Co./company/My App/Backend/"
Any idea how I can use the special chars path and get vagrant up to run properly?
I was finally able to fix this.
Move the directory to some path without special characters, such as ~/Desktop in this case.
Update the Homestead.yaml file and insert the new path: map: ~/Desktop/Backend/app
now, cd into the new directory and run $ vagrant up
$ vagrant ssh should also work now
$ cd app - try to call an API method
$ exit
$ vagrant halt
move the directory to the desired path
cd into the new directory, edit the Homestead.yaml file: map: ~/Desktop/Apps & Co./company/My App/Backend/ (no escapes, nothing)
$ vagrant up
$ vagrant ssh
$ cd app
Now it should work in the desired directory.
I have a playbook with the following task that must copy the 2 Gb file from local to remote servers and extract files:
- name: Copy archived file to target server and extract
unarchive:
src: /path_to_source_dir/file.tar.gz
dest: /path_to_dest_dir
This task fails because ansible copies file to /home mount point on the target server and there's not enough space there:
sftp> put /path_to_source_dir/file.tar.gz /home/my_user_name/.ansible/tmp/ansible-tmp-1551129648.53-14181330218552/source
scp: /home/my_user_name/.ansible/tmp/ansible-tmp-1551129648.53-14181330218552/source: No space left on device
The reason for that is because ansible.cfg has a default parameter:
remote_tmp = ~/.ansible/tmp
How to overwrite this parameter from the playbook (if possible) and make ansible to copy file to the same destination directory specified in the task? So it would be like this:
remote_tmp = /path_to_dest_dir/.ansible/tmp
And the destination path is going to be different each time for a different target server!
Cleaning /home is not an option for me.
The answer here unfortunately is not very clear to me.
There are a few different ways to achieve what you are looking to do. Which one is a matter of preference and your use case.
You found the first way, setting an environment variable before running the playbook. Great for a quick on-the-fly job. Remembering to do that every time you run a certain playbook is indeed annoying. A slight variation of that is to use the environment keyword to set that variable for the play. You can also set environment variable in a role, block or a single task. https://docs.ansible.com/ansible/devel/reference_appendices/playbooks_keywords.html?highlight=environment%20directive. Here is an example of it in use: https://docs.ansible.com/ansible/devel/reference_appendices/faq.html?highlight=environment.
Using the environment keyword in a play et al works well for a specific application of automation, but what if you want Ansible to always use a different remote tmp path for specific servers? Like all variables, the remote_tmp can be sourced from inventory host and group variables not just the config file or environment variables. You need to mind you variable precedence if it is being set in different places. With this you could set remote_tmp in your inventory for that host or a group of hosts. Ansible will always use that path for that host or hosts in that group without having to define it in every play or roles. If you need to change that path, you change it in your inventory and it changes the behavior for all playbook runs without any additional edits. Here is an example of it being used as a host variable in static inventory: https://docs.ansible.com/ansible/devel/reference_appendices/faq.html?highlight=remote_tmp#running-on-solaris
So while the specific issue of "dynamically" setting the remote tmp directory on a host is not a best practice topic per se, it does become an example of the best practice of making the most of variables in Ansible.
For reference, remote temporary directories are handled by the shell plugins. While many parameters are shared, there are others that are specific to the shell Ansible using. Ansible uses sh by default. https://docs.ansible.com/ansible/latest/plugins/shell/sh.html
Hope that helps. Happy automating.
How do I share a single file, instead of sharing a whole folder like
config.vm.synced_folder "host/folder", "box/folder"
?
In other words is there a way to have something like:
config.vm.synced_folder "host/folder/file.conf", "box/folder/file.conf"
The accepted answer (by cdmo) didn't work for me, but was close and led me to the right solution, so cheers. To copy just one file I needed to change it to:
config.vm.synced_folder "c:/hostpath/", "/guestpath/", type: "rsync",
rsync__args: ["-r", "--include=file.text", "--exclude=*"]
Mind the arguments and their order, -r MUST be present and --include MUST precede --exclude.
If needed, instead of -r option you may use -a option which combines -r with several other options for preservation of permissions, ownership etc. (see rsync help).
My testing configuration: Vagrant 2.0.2/Win10/VirtualBox 5.2.6
Use the include flag in your rsync args array:
config.vm.synced_folder "host/folder/", "box/folder/", type: "rsync",
rsync__args: ["--include=file.conf"]
You can use the file provisioner to do this:
Vagrant.configure("2") do |config|
# ... other configuration
config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
end
You can't synchronize a single file. But maybe you can achieve the same effect by synchronizing the folder using RSync with the rsync__exclude option:
rsync__exclude (string or array of strings) - A list of files or directories to exclude from the sync. The values can be any acceptable rsync exclude pattern.
Vagrant by default utilizes the file/folder synchronization mechanisms offered by the provider technologies (e.g., VirtualBox, VMWare, etc.). If the providers can't do synchronization on a per-file basis, then Vagrant can't either. Vagrant can also use NFS, RSync, or SMB for file synchronization. However, looking at the code, it would appear that each expects the per-folder paradigm.
Another possibility is to use one of the provisioning options to selectively synchronize the appropriate file(s). If you want to take the easy way out you could use the shell provisioner to just copy the file you need. For something more interesting, this is a reasonable guide to getting started with Puppet in Vagrant, and you might be interested in the puppet file Type.
As Benjamin Mosior explained, you can only synchronise a whole folder.
As a workaround, I ended up synchronising the whole folder to a temporary folder and in a later step creating a symlink where I need it to the single file inside this temporary folder.
I cannot run vagrant due to this error. I've posted my homestead.yaml code image.
Per your screenshot it looks like the last line of your yaml file is not correctly indented (you have extra space before value). It must be
variables:
- key: APP_ENV
value: local