From 54a4fdd79523efacdff9263695b816e952980124 Mon Sep 17 00:00:00 2001 From: Yaroslav Podorvanov Date: Sat, 7 Oct 2023 02:16:54 +0300 Subject: [PATCH] sync with github.com/readytotouch-yaaws/yaaws-go --- Makefile.ansible | 23 ++----- scripts/ansible/git-pull.yml | 44 ++++---------- .../install-docker-compose-playbook.yml | 58 ------------------ scripts/ansible/install-docker-compose.yml | 60 +++++++++++++++++++ .../{go-install.yml => install-go.yml} | 5 +- scripts/ansible/install-nodejs.yml | 29 +++++++++ scripts/ansible/make.yml | 22 ------- 7 files changed, 111 insertions(+), 130 deletions(-) delete mode 100644 scripts/ansible/install-docker-compose-playbook.yml create mode 100644 scripts/ansible/install-docker-compose.yml rename scripts/ansible/{go-install.yml => install-go.yml} (82%) create mode 100644 scripts/ansible/install-nodejs.yml delete mode 100644 scripts/ansible/make.yml diff --git a/Makefile.ansible b/Makefile.ansible index b657353..19c1d83 100644 --- a/Makefile.ansible +++ b/Makefile.ansible @@ -1,25 +1,14 @@ ansible-ping: - # https://askubuntu.com/questions/46424/how-do-i-add-ssh-keys-to-authorized-keys-file - # https://askubuntu.com/a/262074 - # cat ~/.ssh/id_rsa.pub | ssh root@70.34.254.126 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" ansible -i ./scripts/ansible/hosts.txt all -m ping -ansible-install-docker-compose: - # https://docs.ansible.com/ansible/latest/network/getting_started/first_playbook.html - ansible-playbook -i ./scripts/ansible/hosts.txt ./scripts/ansible/install-docker-compose-playbook.yml - ansible-git-pull: ansible-playbook -i ./scripts/ansible/hosts.txt ./scripts/ansible/git-pull.yml -# alias -agp: ansible-git-pull - -ansible-make: - ansible-playbook -i ./scripts/ansible/hosts.txt ./scripts/ansible/make.yml +ansible-install-docker-compose: + ansible-playbook -i ./scripts/ansible/hosts.txt ./scripts/ansible/install-docker-compose.yml -ansible-shell: - # ansible -i ./scripts/ansible/hosts.txt all -m shell -a "ps aux" - ansible -i ./scripts/ansible/hosts.txt all -m shell -a "cd /var/go/u8views; env" +ansible-install-go: + ansible-playbook -i ./scripts/ansible/hosts.txt ./scripts/ansible/install-go.yml -ansible-go-install: - ansible-playbook -i ./scripts/ansible/hosts.txt ./scripts/ansible/go-install.yml +ansible-install-nodejs: + ansible-playbook -i ./scripts/ansible/hosts.txt ./scripts/ansible/install-nodejs.yml diff --git a/scripts/ansible/git-pull.yml b/scripts/ansible/git-pull.yml index 7799492..bfc23d9 100644 --- a/scripts/ansible/git-pull.yml +++ b/scripts/ansible/git-pull.yml @@ -1,37 +1,19 @@ --- -# https://fabianlee.org/2021/02/03/ansible-cloning-a-git-repository-that-requires-credentials/ - name: "Git clone u8views" - hosts: web - gather_facts: no + hosts: "web" + gather_facts: "no" + vars: + - REPOSITORY: "https://github.com/u8views/go-u8views.git" + - DESTINATION: "/var/go/u8views" tasks: - - name: "/var/go/u8views" - file: - path: /var/go/u8views - state: directory + - name: "Ensure directory {{ DESTINATION }} exists" + ansible.builtin.file: + path: "{{ DESTINATION }}" + state: "directory" - - name: "git pull" + - name: "Git pull repository {{ REPOSITORY }}" ansible.builtin.git: - repo: https://github.com/u8views/go-u8views.git - version: main - dest: /var/go/u8views - - - name: "git status" - shell: "git status" - args: - chdir: "/var/go/u8views" - register: out - when: false - - debug: - var: out.stdout_lines - when: false - - - name: "ls -la" - shell: "ls -la" - args: - chdir: "/var/go/u8views" - register: out - when: false - - debug: - var: out.stdout_lines - when: false + repo: "{{ REPOSITORY }}" + version: "main" + dest: "{{ DESTINATION }}" diff --git a/scripts/ansible/install-docker-compose-playbook.yml b/scripts/ansible/install-docker-compose-playbook.yml deleted file mode 100644 index ee73c03..0000000 --- a/scripts/ansible/install-docker-compose-playbook.yml +++ /dev/null @@ -1,58 +0,0 @@ ---- -# https://cloudinfrastructureservices.co.uk/how-to-install-docker-compose-using-ansible-playbook/ -# https://support.netfoundry.io/hc/en-us/articles/360057865692-Installing-Docker-and-docker-compose-for-Ubuntu-20-04 -- name: "Install docker-compose" - hosts: web - gather_facts: no - tasks: - - name: "sudo apt update" - apt: - update_cache: yes - - - name: "docker dependencies" - apt: - name: - - "apt-transport-https" - - "ca-certificates" - - "curl" - - "software-properties-common" - state: present - update_cache: yes - - - name: "docker's gpg key" - apt_key: - url: https://download.docker.com/linux/ubuntu/gpg - state: present - - - name: "configure docker repository" - apt_repository: - repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable - state: present - - - name: "sudo apt update" - apt: - update_cache: yes - - - name: "docker-ce" - apt: - name: docker-ce - state: present - update_cache: yes - - - name: "docker --version" - shell: "docker --version" - register: out - - debug: - var: out.stdout - - - name: "install docker-compose from official GitHub repository" - get_url: - url: https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-{{ lookup('pipe', 'uname -s') }}-{{ lookup('pipe', 'uname -m') }} - dest: /usr/local/bin/docker-compose - mode: 'u+x,g+x' - - - name: "docker-compose --version" - shell: "docker-compose --version" - register: out - - debug: - var: out.stdout \ No newline at end of file diff --git a/scripts/ansible/install-docker-compose.yml b/scripts/ansible/install-docker-compose.yml new file mode 100644 index 0000000..412fcc7 --- /dev/null +++ b/scripts/ansible/install-docker-compose.yml @@ -0,0 +1,60 @@ +--- +- name: "Install Docker and Docker Compose" + hosts: "web" + gather_facts: "no" + vars: + - DOCKER_COMPOSE_VERSION: "2.22.0" + + tasks: + - name: "Update apt cache" + apt: + update_cache: "yes" + + - name: "Install required packages" + package: + name: "{{ item }}" + state: "present" + loop: + - "apt-transport-https" + - "ca-certificates" + - "curl" + - "software-properties-common" + + - name: "Add Docker GPG key" + apt_key: + url: "https://download.docker.com/linux/ubuntu/gpg" + state: "present" + + - name: "Add Docker APT repository" + apt_repository: + repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" + state: "present" + + - name: "Install Docker" + package: + name: "docker-ce" + state: "present" + + - name: "Start and enable Docker service" + service: + name: "docker" + state: "started" + enabled: "yes" + + - name: "Install Docker Compose" + get_url: + url: "https://github.com/docker/compose/releases/download/v{{ DOCKER_COMPOSE_VERSION }}/docker-compose-{{ lookup('pipe', 'uname -s') }}-{{ lookup('pipe', 'uname -m') }}" + dest: "/usr/local/bin/docker-compose" + mode: "a+x" + + - name: "Get Docker version" + command: "docker --version" + register: "docker_version" + - debug: + var: "docker_version.stdout" + + - name: "Get Docker Compose version" + command: "docker-compose --version" + register: "docker_compose_version" + - debug: + var: "docker_compose_version.stdout" diff --git a/scripts/ansible/go-install.yml b/scripts/ansible/install-go.yml similarity index 82% rename from scripts/ansible/go-install.yml rename to scripts/ansible/install-go.yml index 90d0f6c..04473f1 100644 --- a/scripts/ansible/go-install.yml +++ b/scripts/ansible/install-go.yml @@ -21,8 +21,9 @@ - name: "Add Go binaries to PATH" lineinfile: path: "~/.profile" - line: "export PATH=$PATH:/usr/local/go/bin" - create: "yes" + line: "{{ item }}" + state: "present" + loop: "{{ ['export GOROOT=/usr/local/go', 'export GOPATH=$HOME/go', 'export PATH=$GOPATH/bin:$GOROOT/bin:$PATH'] }}" - name: "Source ~/.profile" shell: "source ~/.profile; go version" diff --git a/scripts/ansible/install-nodejs.yml b/scripts/ansible/install-nodejs.yml new file mode 100644 index 0000000..fce6e4c --- /dev/null +++ b/scripts/ansible/install-nodejs.yml @@ -0,0 +1,29 @@ +--- +- name: "Install Node.js and npm" + hosts: "web" + gather_facts: "no" + + tasks: + - name: "Update apt cache" + apt: + update_cache: "yes" + + - name: "Install Node.js and npm" + apt: + name: + - "nodejs" + - "npm" + state: "present" + + - name: "Get Node.js version" + shell: "node -v" + register: "node_version" + - debug: + var: "node_version.stdout" + + + - name: "Get npm version" + shell: "npm -v" + register: "npm_version" + - debug: + var: "npm_version.stdout" diff --git a/scripts/ansible/make.yml b/scripts/ansible/make.yml deleted file mode 100644 index 1702f8d..0000000 --- a/scripts/ansible/make.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: "Make" - hosts: web - gather_facts: no - vars_prompt: - - name: command - private: no - - tasks: - - name: "Make exists" - apt: - name: - - "make" - state: present - - - name: "make --makefile=Makefile.server {{ command }}" - make: - chdir: "/var/go/u8views" - target: "{{ command }}" - register: out - - debug: - var: out.stdout_lines