How To Install Ansible

System Env

  • OS info
    [root@ansible /]# cat /etc/redhat-release
    CentOS Linux release 7.6.1810 (Core)
    [root@ansible /]# lsb_release -a
    LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
    Distributor ID: CentOS
    Description: CentOS Linux release 7.6.1810 (Core)
    Release: 7.6.1810
    Codename: Core
    

Install Python36

  • upgrade system pkgs
    [root@ansible /]# yum clean all && yum makecache
    [root@ansible /]# yum upgrade -y
    
  • install python36
    [root@ansible /]# yum install epel-release -y
    [root@ansible /]# yum clean all && yum makecache
    [root@ansible /]# yum install python36 python36-devel python36-pip -y
    
  • set pip3.6 as the default pip
    [root@ansible /]# pip3.6 install --upgrade pip
    

Install Ansible

[root@ansible /]# pip install ansible

Run it in Docker

  • write a Dockerfile
    [root@DockerServer /]# cat Dockerfile
    FROM centos:latest
    MAINTAINER Kyle Chen
    ENV LANG C.UTF-8
    ENV DEBIAN_FRONTEND=noninteractive
    RUN yum clean all && \
    yum makecache && \
    yum upgrade -y && \
    yum install vim openssh-server epel-release -y && \
    yum clean all && \
    yum makecache && \
    yum install python36 python36-devel python36-pip -y && \
    echo "set -o vi" >> /etc/bashrc && \
    pip3.6 install --upgrade pip && \
    pip install ansible && \
    echo "PASSWORD" | passwd --stdin USER && \
    systemctl enable sshd
    
  • build an image
    [root@DockerServer /]# docker build . -t ansible
    
  • run image
    [root@DockerServer /]# docker run --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro --ip IP --dns DNS --name ansible --hostname ansible -tdi ansible:latest /usr/sbin/init
    
  • ATTENTION:
    You must set the PASSWORD, USER, IP, DNS which can be found before you run image. After run image, you can use 'ssh USER@IP' and input password to login on the server.

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据