Ansible install and get you started

I. Introduction

       Puppet, SaltStack, Chef, Ansible server batch operation and maintenance are commonly used tools, which Ansible biggest bright spot is "no client, easy to use and centralized management log.", Do not help each machine (instance) preloaded agent, as long as you can SSH and Python. This paper introduce the basic use of Ansible.

 

Second, the structure

 

  1, when the Control Machine (master) can connect with SSH Managed node, and is connected to the machine when there are pre-load Python, Ansible can operate up!

  2, Managed node is manipulated Ansible machine.

 

Third, the installation Ansible in the Control Machine

Ubuntu (Apt) 

    install the Add -apt- Repository necessary kit. 
    $ Sudo APT-GET install -y the Properties Python-Software-Software-PROPERTIES- Free Real Time the Common 

    Use Ansible official PPA package sources. 
    $ The sudo the Add-APT Repository -Y-PPA: ansible / ansible; the sudo APT- GET Update 

    Installation Ansible. 
    $ Sudo APT-GET install - the y-ansible 


CentOS (Yum) 

    New EPEL - Release suite of third-party sources. 
    $ Sudo  yum  install -y epel- Release 

    installation Ansible. 
    $sudo  yum  install - the y-ansible 


macOS (Homebrew) 

    Please install homebrew, already installed, please skip. 
    $ / Usr / bin / Ruby -e " $ (curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) " 

    installation Ansible. 
    BREW $ install ansible 

Python (Pip) 
    Ansible speed recently released soon, if you want to pursue a newer version could be replaced by Pip way to install, less is recommended for beginners. 
    Need to install the pip, already installed, please skip. 
    Debian #, Ubuntu 
    $ sudo APT-GET install -y Python - PIP 


    # CentOS 
    $ sudo  yum  install -y Python - PIP
    
    # macOS
    $ sudo easy_install pip
    
    升级 pip。
    $ sudo pip install -U pip
    
    安装 Ansible。
    $ sudo pip install ansible

 

 

Fourth, the installation and SSH Python in the Managed node (comes with a system, and thus can omit this step)

Ubuntu.
$ sudo apt-get install -y openssh-server python2.7

CentOS.
$ sudo yum install -y openssh-server python

 

Fifth, modify the configuration

  1, installed after Ansible, we can see the configuration files in / etc / ansible directory. Modify: ansible.cfg, such as:

inventory = hosts 
remote_user = root 
host_key_checking=False

   2, modify / etc / ansible / hosts file, see the diagram, can use the following variables: ansible_ssh_host, ansible_ssh_port, ansible_ssh_user, ansible_ssh_pass, ansible_ssh_private_key_file.

  

  For example, I use test configuration:

  

 

 

Five test

  1, the under / etc / ansible directory, execute: vim ./helloworld.yml follows:

---

- name: say 'hello world'
  hosts: huawei
  tasks:

    - name: echo 'hello world'
      command: echo 'hello world'
      register: result

    - name: print stdout
      debug: var=result
                            

  2, execute: ansible-playbook ./helloworld.yml

  

 

 

  3、

 

Guess you like

Origin www.cnblogs.com/songxingzhu/p/12450275.html