Ansible playbook: pipeline local cmd output (e,g. git archive) to server? - deployment

So my project has a special infrastructure, the server has only SSH connection, I have to upload my project code to server using SSH/SFTP everytime, manually. The server can not fetch.
Basically I need something like git archive master | ssh user#host 'tar -zxvf -' automatically done using playbook.
I looked at docs, local_action seems to work but it requires a local ssh setup. Are there other ways around?

How about something like this. You may have to tweak to suit your needs.
tasks:
- shell: git archive master /tmp/master.tar.gz
- unarchive: src=/tmp/master.tar.gz dest={{dir_to_untar}}
I still do not understand it requires a local ssh setup in your question.

Related

How to deploy docker-compose solution automatically from github to vps over ssh?

What I want to do:
Deploy docker-compose solution from Github to my virtual private server which has docker and docker-compose installed.
I saw that there are Github Actions that allow me to copy files over SSH after push to master, but I don't know how to run docker-compose up on my server after source has been copied.
On my VPS I have Ubuntu 18.4 installed.
I believe Github actions also allow you to run arbitrary commands on remote servers via ssh (there are a few in their library).
Assuming you copy your docker-compose.yml into, /home/user/app/docker-compose.yml, you could run a command like so:
ssh user#yourserver.example.com "cd /home/user/app/ && docker-compose up -d"

ncftp deployment (via butbucket pipelines) getting "server said: www: no such file or directory" but path in filezilla is exactly right

I'm trying to automate deployment via ftp via bitbucket pipelines.
Path is:
/var/www/vhosts/maindomain.com/subdomain.maindomain.com
Tried it with and without the first forward slash in there. Also checked the default path when you connect and its maindomain.com/subdomain.maindomain.com -- tried that too but same error.
Code looks like this:
image: node:9.8.0
pipelines:
default:
- step:
name: Deployment
script:
- apt-get update
- apt-get install ncftp
- ncftpput -v -u "$FTP_USERNAME" -p "$FTP_PASSWORD" -R $FTP_HOST $FTP_SITE_ROOT dist/*
- echo Finished uploading /dist files to $FTP_HOST$FTP_SITE_ROOT
But the problem is ncftp doesn't like the file path to upload no matter what. I've been using the one showing up in filezilla after navigating to that folder whilst connecting with the exact same credentials.
How could I trackdown the right path or troubleshoot this forward?
I think the problem lies with my server only accepting SFTP connections and can't set port to 22 as NCFTP does not support SSH. I'm currently look at lftp as an alternative, will post here the syntax if I figure it out.
Edit: Does not scale well, will be pursuing different avenues for continuous deployment.
Don't need to add the full path of FTP site just put the path as below.
-R /maindomain.com/subdomain.maindomain.com dist/*
for check the physical path of site, site->manage ftp site-> advance setting.
where you find the physical path that we don't need to include when we use cli.

What is the best practice to move my dockerfile and related files to the server? (private files)

I have a dockerfile, a .sh file, a nginx config file and the private keys. But on a clean server how to add those files for the first time (before making the docker image) to the server?
Should I FTP and put those files there?
Should I git pull my project? // but I still need the keys or I can use password
What you do?
I'm not using digital ocean, and I would not like to have a private paid docker repo like https://registry.hub.docker.com/plans/
You use a physical server or a vps ?
If you can ssh to your server, add files have so many ways.
1.The most easy way is use sftp (you can find some sftp client to do this or use ftp command line tools), only need your ssh login permission, and you can upload these file to your user home directory.
2.The other way is use scp, command like:
scp YOUR_FILE username#ipaddressORhostname:/home/username/
this also only need your ssh login permission
git or ftp is not a good way to push files fisrt time to server.
Most git remotes repos (GitHub, GitLab etc) will support a https access mechanism, the data is encrypted in transit much like sftp and ssh. you'll get a password challenge. No keys...
git remote add myHttpsRemote https://my/foo/bar/project.git
git pull myHttpsRemote [branch]

SSH versus FTP: Push local files to a server via Terminal

I am a junior front-end developer and I am working on my process using command line. I would like to push my local changes to my server without having to use an FTP client like Filezilla. I am manually dragging and dropping files using the client and would like to learn how developers perform this process. I am building a static site using SiteLeaf on a Mac. Thanks in advance for help with this workflow.
If your target has SSH installed you can use SCP:
$ scp -r your_remote_user#remote_address:/path/to/save/dir /local/dir/to/transfer
This can also be used to transfer single files: just remove the -r (recursive) option and specify files path instead of directories.

Capistrano Net::SSH::Authentification::AgentError

I'm trying to set up capistrano for pushing my project, using git as VCS.
I'm running capistrano on a win7 machine, and want to push on my ubuntu 64bit EC2, here is what capistrano says: http://pastebin.com/FRyzYFbE
My local SSH Client is Putty, and works pretty fine, for my deploy.rb i've set something like: http://pastebin.com/UubfdDYm
Does anyone know what's going on there?
I don't have Win7, but I can tell you what worked for me on winXP. I added an SSH config file to %USER_HOME%/.ssh/config
The contents of that file look like this:
Host dev
User ubuntu
Hostname example.com
IdentityFile path/relative/to/user_home_ssh/mykey.ppk
The Host line can be the actual host or a nickname that you will use. Here, I used a short nickname. This should match the IP or hostname you use in your capistrano config.
The User should be the user you set in your capistrano config (ubunto in your case).
The Hostname is the real hostname or IP of the server you will access. The IdentityFile is a path relative to your USER_HOME/.ssh directory.
Ok, I found out that, because i have Git installed, the home directory for my ssh config is C:\Program Files\Git\.ssh
I had to fi several things there, and when it first works to connect via ssh in the command line (thanks to Git i have an SSH client installed), the connection was successfull.
There is still a bug, cause Capistrano can't do a local git command due to SSH key error, if i do the same command in the CLI, it works perfeclty. But I think I will stop using capistrano and use something easier, a remot git pull && /build.sh should do the trick.