Ansible Getting Started

目录

Notice: base on Ubuntu 14.04

Prepare

  • Python > 2.5
    • easy_install: sudo apt-get install python-setuptools
    • pip: sudo easy_install pip
  • Others
    • sudo pip install paramiko PyYAML Jinja2 httplib2

Installation(Ubuntu)

  • sudo apt-get install software-properties-common
  • sudo apt-add-repository ppa:ansible/ansible
  • sudo apt-get update
  • sudo apt-get install ansible

Enviroment Configuration

  • Generating SSH keys

  • upload ssh key for SSH login without password

  • set up SSH agent to avoid retyping passwords

    • ssh-agent bash
    • ssh-add ~/.ssh/id_rsa

Make some tests

  • ping

      # as bruce
      $ ansible all -m ping -u bruce
      # as bruce, sudoing to root
      $ ansible all -m ping -u bruce --sudo
      # as bruce, sudoing to batman
      $ ansible all -m ping -u bruce --sudo --sudo-user batman
    
  • echo hello

      $ ansible all -a "/bin/echo hello"