Ansible install docker to Ubuntu

About ansible

Ansible is a radically simple IT automation system. It handles configuration management, application deployment, cloud provisioning, ad-hoc task execution, network automation, and multi-node orchestration. https://github.com/ansible/ansible

Install ansible with pip

please make sure you have install python3.

To verify whether pip is already installed for your preferred Python

python3 -m pip -V        

I use the python enve environment install ansible

python3 -m venv .ansible_python # new venv environment named ansible_python

source .ansible_python/bin/activate # activate the environment
        

Then install the ansible

pip install ansible        

Set ansible configration

vim /home/USER1/.ansible/ansible.cfg        
[web_server]
# name ansible_host ansible_ssh_user ansible_ssh_private_key_file 
web1 ansible_host=192.168.1.21 ansible_ssh_user=user1 ansible_ssh_private_key_file=/home/USER1/.ssh/id_ed25519
web2 ansible_host=192.168.1.46 ansible_ssh_user=user1 ansible_ssh_private_key_file=/home/USER1/.ssh/id_ed25519
web3 ansible_host=172.xxx.xxx.xxx ansible_ssh_user=root ansible_ssh_private_key_file=/home/USER1/.ssh/id_ed25519
        

more information please visit https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#inventory-basics-formats-hosts-and-groups

My first ansible test

ansible -i /home/USER1/.ansible/ansible.cfg web1 -m shell -a "df -h"        

All server

ansible -i /home/USER1/.ansible/ansible.cfg all -m shell -a "df -h"        

Use ansible-playbook install docker to the server

Add new ansible-playbook configuration file

vim /home/USER1/.ansible/docker_install_playbook.yml        
---
- hosts: all
  become: true

  tasks:
    - name: Install aptitude
      apt:
        name: aptitude
        state: latest
        update_cache: true

    - name: Install required system packages
      apt:
        pkg:
          - apt-transport-https
          - ca-certificates
          - curl
          - software-properties-common
        state: latest
        update_cache: true

    - name: Add Docker GPG apt Key
      apt_key:
        url: https://download.docker.com/linux/ubuntu/gpg
        state: present

    - name: Add Docker Repository
      apt_repository:
        repo: deb https://download.docker.com/linux/ubuntu focal stable
        state: present

    - name: Update apt and install docker-ce
      apt:
        name: docker-ce
        state: latest
        update_cache: true
        

install to web3 server

ansible-playbook docker_install_playbook.yml -i  /home/USER1/.ansible/ansible.cfg -l web3        

要查看或添加评论,请登录

Jiangbo Li的更多文章

  • About CIDR

    About CIDR

    What is 10.105.

  • Docker Swarm

    Docker Swarm

    Docker Swarm Initialization 1.Install Docker and initial Skip 2.

  • Start from Hashicorp Vault

    Start from Hashicorp Vault

    What is the Hashicorp Vault key feature HashiCorp Vault is an open-source tool designed for securely managing secrets…

  • About CI/CD

    About CI/CD

    What is you want about CI/CD Safe Reversible Provide no down time Deployment Rolling Deploymen(Phased Deployment)…

  • Linux chattr command

    Linux chattr command

    chattr (Change Attribute) is a command line Linux utility that is used to set/unset certain attributes to a file in…

  • Setup Webdav using Caddy at Ubuntu

    Setup Webdav using Caddy at Ubuntu

    Install Caddy Server Please see this link https://caddyserver.com/docs/install Install Caddy Webdav module Configuring…

  • Notification when ssh login

    Notification when ssh login

    I want to keep an eye on SSH logins to a particular server. For this, I've opted for the 'ntfy' service to send push…

社区洞察

其他会员也浏览了