Work in progress
This commit is contained in:
		
							parent
							
								
									6f485fa7f9
								
							
						
					
					
						commit
						781dd2e51b
					
				| @ -1,6 +1,6 @@ | |||||||
| --- | --- | ||||||
| - name: DockerAPI Install | - name: DockerAPI Install | ||||||
|   hosts: <CHANGE_ME> |   hosts: <CHANGE_HOSTS> | ||||||
|   become: yes |   become: yes | ||||||
|   tasks: |   tasks: | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										21
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								README.md
									
									
									
									
									
								
							| @ -1,9 +1,20 @@ | |||||||
| # Ansible-Deploy-Docker | # Ansible-Deploy-Docker | ||||||
| Simple ansible playbook to deploy latest docker/docker-compose via ansible. | Simple ansible playbook to deploy latest docker and docker-compose via ansible. | ||||||
| 
 | 
 | ||||||
| Remember to change <CHANGE_ME> in playbook and <YOUR KEY HERE> in bash script. | ## Edit configs | ||||||
| 
 | 
 | ||||||
| Also a bash script that creates a "ansible" user. You'll need to write your public key in script. | ### add_ansible_user.sh | ||||||
| 
 | 
 | ||||||
| It is a good option to create a paswordless ssh key and copy it onto every machine you want to work with. | __<ANSIBLE_USERNAME>__ -- Set a username for ansible. Example "ansible" | ||||||
| Bash script is configured to work only with public keys. | 
 | ||||||
|  | __<YOUR_PUBKEY>__ -- Paste your public key. | ||||||
|  | 
 | ||||||
|  | __UID_INT__ -- This is optional. By default it is set to 1600. It makes it easier to distinguish ansible user from the rest  | ||||||
|  | 
 | ||||||
|  | ### DockerEngineInstall.yml | ||||||
|  | 
 | ||||||
|  | The only thing to change here is __<CHANGE_HOSTS>__ at line 3. There you need to input IP of computers that ansible will run this playbook on. | ||||||
|  | 
 | ||||||
|  | ## PS | ||||||
|  | 
 | ||||||
|  | In Proxmox if you have a VM template it is possible to paste multiple pubkeys. Go to template -> Cloud-Init -> SSH public key -> edit -> paste your pubkeys. | ||||||
|  | |||||||
| @ -1,36 +1,47 @@ | |||||||
| #!/bin/bash | #!/bin/bash | ||||||
| 
 | 
 | ||||||
| # Define the username | # Define variables | ||||||
| USERNAME="ansible" | USERNAME="<ANSIBLE_USERNAME>" | ||||||
|  | PUBLIC_KEY="<YOUR_PUBKEY>" | ||||||
|  | UID_INT="1600"  # 1600 to easilly distinguish ansible_user | ||||||
|  | not_found=0 | ||||||
| 
 | 
 | ||||||
| # Define the public key (replace with your actual public key) | # Check if user exists | ||||||
| PUBLIC_KEY="<YOUR KEY HERE>" | IFS=$'\n' | ||||||
|  | for users in $(cat /etc/passwd) | ||||||
|  | do | ||||||
|  |     if [[ $(echo "$users" | awk 'BEGIN { FS = ":" } ; { print $1 }') = "$USERNAME" ]] | ||||||
|  |     then | ||||||
|  |         ((not_found++)) | ||||||
|  |     fi  | ||||||
|  | done | ||||||
|  | unset IFS | ||||||
| 
 | 
 | ||||||
| # Create the user if it doesn't already exist | # Create user with custom UID and GID | ||||||
| if id "$USERNAME" &>/dev/null; then | if [[ $not_found = 0 ]]; then | ||||||
|   echo "User '$USERNAME' already exists." |     echo "Creating user '$USERNAME'..." | ||||||
|  |     sudo useradd -m "$USERNAME" -s "/bin/bash" -u $UID_INT | ||||||
| else | else | ||||||
|   echo "Creating user '$USERNAME'..." |     echo "User '$USERNAME' already exists." | ||||||
|   sudo useradd -m "$USERNAME" |  | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # Create the .ssh directory in the user's home directory if it doesn't exist | # Create the .ssh directory if it doesn't exists | ||||||
| HOME_DIR="/home/$USERNAME" | HOME_DIR="/home/$USERNAME" | ||||||
| SSH_DIR="/home/$USERNAME/.ssh" | SSH_DIR="/home/$USERNAME/.ssh" | ||||||
| if [ ! -d "$SSH_DIR" ]; then | if [[ ! -d "$SSH_DIR" ]]; then | ||||||
|   echo "Creating $SSH_DIR directory..." |     echo "Creating $SSH_DIR directory..." | ||||||
|   sudo -u "$USERNAME" mkdir -p "$SSH_DIR" |     sudo -u "$USERNAME" mkdir -p "$SSH_DIR" | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # Paste the public key directly into authorized_keys | # Paste the public key directly into authorized_keys | ||||||
| echo "$PUBLIC_KEY" | sudo -u "$USERNAME" tee "$SSH_DIR/authorized_keys" > /dev/null | echo "$PUBLIC_KEY" | sudo -u "$USERNAME" tee -a "$SSH_DIR/authorized_keys" > /dev/null | ||||||
| 
 | 
 | ||||||
| # Set correct permissions | # Set correct permissions | ||||||
| echo "Setting permissions..." | echo "Setting permissions..." | ||||||
| sudo -u "$USERNAME" chmod 755 "$HOME_DIR" | sudo -u "$USERNAME" chmod 755 "$HOME_DIR" | ||||||
| sudo -u "$USERNAME" chmod 700 "$SSH_DIR" | sudo -u "$USERNAME" chmod 700 "$SSH_DIR" | ||||||
| sudo -u "$USERNAME" chmod 644 "$SSH_DIR/authorized_keys" | sudo -u "$USERNAME" chmod 644 "$SSH_DIR/authorized_keys" | ||||||
| sudo -u "$USERNAME" chown -R "$USERNAME:$USERNAME" "$SSH_DIR" | sudo -u "$USERNAME" chown -R "$USERNAME:" "$SSH_DIR" | ||||||
| 
 | 
 | ||||||
| # Add the user to the sudoers file with NOPASSWD privileges | # Add the user to the sudoers file with NOPASSWD privileges | ||||||
| echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers > /dev/null | echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers > /dev/null | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user