* Fedora Minimal does not come with tar. Need installed for Telegraf. * First attempt at automating HTTP git server setup. * Add cron jobs to keep projects up to date. * Add new git playbook to server. * Add new server variables for git. Put all variables in a dictionary. * Put variables into run file. * Fix the loop variables to be dictionaries, not jinja. * Upgrade nanominer. * Attempt to fix templating error. * Attempt to fix templating error, but in the right spot this time. :) * Attempt another fix for building list of dictionaries. * Change strings to dicts. * Add quotes for jinja variables. * Remove extra curly brackets. * Fix the rest of the file's dictionaries now that General works. * Remove testing code. * Variablize ansible repo. Begin watching personal repos rather than pinging GitHub. * Fix variables to append, not replace. * Fix variable names. * Try to prevent variables from being strings, without getting formatting error. * Try to fix variables, again. * Fixed git.yml. Found a way to test locally and all is working now.
		
			
				
	
	
		
			172 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
			
		
		
	
	
			172 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
| ---
 | |
| # Webserver to replace calling GitHub for projects.
 | |
| # https://www.howtoforge.com/how-to-install-http-git-server-with-nginx-on-debian-11/
 | |
| 
 | |
| ## Variables ##
 | |
| 
 | |
| - name: Server | Software | Git | Check Config Variables
 | |
|   debug: 
 | |
|     var: "{{ item }}"
 | |
|   loop:
 | |
|     - git_name
 | |
|     - git_branch
 | |
|     - git_url
 | |
|     - git_sep
 | |
| 
 | |
| - name: Server | Software | Git | Split Config Variables To Array
 | |
|   set_fact:
 | |
|     git_names: "{{ git_name.split(git_sep) }}"
 | |
|     git_branches: "{{ git_branch.split(git_sep) }}"
 | |
|     git_urls: "{{ git_url.split(git_sep) }}"
 | |
|     git_projects: []
 | |
| 
 | |
| - name: Server | Software | Git | Check Arrays
 | |
|   debug: 
 | |
|     var: "{{ item }}"
 | |
|   loop:
 | |
|     - git_names
 | |
|     - git_branches
 | |
|     - git_urls
 | |
| 
 | |
| - name: Server | Software | Git | Build Dictionary
 | |
|   set_fact:
 | |
|     git_projects: "{{ git_projects + [{ 'name': git_names[item], 'branch': git_branches[item], 'url': git_urls[item]  }] }}"
 | |
|   loop: "{{ range(0, git_names|length) | list }}"
 | |
| 
 | |
| - name: Server | Software | Git | Display Dictionary
 | |
|   debug: 
 | |
|     var: git_projects
 | |
| 
 | |
| - name: Server | Software | Git | Variables 1
 | |
|   set_fact: 
 | |
|     git_web_root: /var/www/html/git
 | |
|     git_config_file: /etc/nginx/conf.d/git.conf
 | |
|     git_nginx_user: www-data
 | |
| 
 | |
| - name: Server | Software | Git | Variables 2
 | |
|   set_fact: 
 | |
|     git_cron_commands: "git pull --rebase && cd {{ git_web_root }}/ && chown -R {{ git_nginx_user }} . && chmod -R 775 ."
 | |
| 
 | |
| 
 | |
| ## Pre-reqs ##
 | |
| 
 | |
| - name: Server | Software | Git | Install
 | |
|   package: 
 | |
|     name:
 | |
|       - nginx
 | |
|       - git
 | |
|       - fcgiwrap
 | |
|       - apache2-utils
 | |
|       - unzip
 | |
|     state: present
 | |
|   when: ansible_pkg_mgr == "apt"
 | |
| 
 | |
| 
 | |
| ## Repositories ##
 | |
| 
 | |
| - name: Server | Software | Git | Delete
 | |
|   file:
 | |
|     path: "{{ git_web_root }}"
 | |
|     state: absent
 | |
| 
 | |
| - name: Server | Software | Git | Download
 | |
|   git: 
 | |
|     repo: "{{ item.url }}"
 | |
|     dest: "{{ git_web_root }}/{{ item.name }}.git"
 | |
|     version: "{{ item.branch }}"
 | |
|     clone: yes
 | |
|     force: yes
 | |
|   #ignore_errors: yes
 | |
|   loop: "{{ git_projects }}"
 | |
| 
 | |
| - name: Server | Software | Git | Permissions
 | |
|   file:
 | |
|     path: "{{ git_web_root }}/{{ item.name }}.git"
 | |
|     state: directory
 | |
|     mode: '755'
 | |
|     owner: "{{ git_nginx_user }}"
 | |
|     group: "{{ git_nginx_user }}"
 | |
|     recurse: yes
 | |
|   loop: "{{ git_projects }}"
 | |
| 
 | |
| 
 | |
| ## NGINX ##
 | |
| 
 | |
| - name: Server | Software | Git | Index
 | |
|   blockinfile:
 | |
|     path: "{{ git_web_root }}/index.html"
 | |
|     block: |
 | |
|       {{ item.name }}.git is cloned from {{ item.url }} using branch {{ item.branch }}.
 | |
|     state: present
 | |
|     mode: '755'
 | |
|     owner: "{{ git_nginx_user }}"
 | |
|     group: "{{ git_nginx_user }}"
 | |
|     create: yes
 | |
|     backup: yes
 | |
|     marker: "<!-- {mark} {{ item.name }} -->"
 | |
|   loop: "{{ git_projects }}"
 | |
| 
 | |
| - name: Server | Software | Git | Config
 | |
|   blockinfile:
 | |
|     path: "{{ git_config_file }}"
 | |
|     block: |
 | |
|       server {
 | |
|         listen 80;
 | |
|       
 | |
|         root {{ git_web_root }};
 | |
|       
 | |
|         # Add index.php to the list if you are using PHP
 | |
|         index index.html;
 | |
|         #autoindex on;
 | |
|       
 | |
|         server_name {{ ansible_hostname }}.{{ domain }};
 | |
|       
 | |
|         location / {
 | |
|           # First attempt to serve request as file, then
 | |
|           # as directory, then fall back to displaying a 404.
 | |
|           try_files $uri $uri/ =404;
 | |
|         }
 | |
|       
 | |
|         location ~ (/.*) {
 | |
|           client_max_body_size 0;
 | |
|           #auth_basic "Hyperling's Git Login";
 | |
|           #auth_basic_user_file "{{ git_web_root }}/htpasswd";
 | |
|           include /etc/nginx/fastcgi_params;
 | |
|           fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
 | |
|           fastcgi_param GIT_HTTP_EXPORT_ALL "";
 | |
|           fastcgi_param GIT_PROJECT_ROOT {{ git_web_root }};
 | |
|           fastcgi_param REMOTE_USER $remote_user;
 | |
|           fastcgi_param PATH_INFO $1;
 | |
|           fastcgi_pass unix:/var/run/fcgiwrap.socket;
 | |
|         }
 | |
|       }
 | |
|     state: present
 | |
|     mode: '755'
 | |
|     create: yes
 | |
|     backup: yes
 | |
|     marker: "# {mark} Managed By Ansible Git Server Playbook -->"
 | |
|     
 | |
| - name: Server | Software | Git | Service
 | |
|   service:
 | |
|     name: nginx
 | |
|     pattern: nginx
 | |
|     enabled: yes
 | |
|     state: restarted
 | |
| 
 | |
| 
 | |
| ## Cron ##
 | |
| 
 | |
| - name: Server | Software | Git | Cron | Hourly
 | |
|   ansible.builtin.cron:
 | |
|     name: "{{ item.name }} hourly"
 | |
|     special_time: hourly
 | |
|     job: "cd {{ git_web_root }}/{{ item.name }}.git && {{ git_cron_commands }}"
 | |
|   loop: "{{ git_projects }}"
 | |
| 
 | |
| - name: Server | Software | Git | Cron | Reboot
 | |
|   ansible.builtin.cron:
 | |
|     name: "{{ item.name }} reboot"
 | |
|     special_time: reboot
 | |
|     job: "cd {{ git_web_root }}/{{ item.name }}.git && {{ git_cron_commands }}"
 | |
|   loop: "{{ git_projects }}"
 |