DEV Community

feng wei
feng wei

Posted on

First Glance at Ansible

What is ansible

Ansible is an open-source IT automation tool that automates provisioning, configuration management, application deployment, orchestration, and many other IT processes. Ansible is written in Python and uses OpenSSH for transport.

Hands-on Ansible

  1. Install ansible on a Linux machine, which is called control node. Use "ssh-keygen" and "ssh-copy-id"commands to generate ssh key and copy it to managed nodes for authentication
  2. Playbooks are the simplest way in Ansible to automate repeating tasks in the form of reusable and consistent configuration files. Playbooks are scripts defined in YAML files and contain any ordered set of steps to be executed on managed nodes.

[My first playbook]

  • hosts: webserver remote_user: whocare

tasks:

  • name: make ~/whocare directory
    ansible.builtin.file:
    path: ~/whocare
    state: directory

  • name: Copy file
    copy:
    src: /home/whocare.deb
    dest: /home/whocare.deb
    owner: whocare
    group: whocare
    mode: '0700'

  • name: install whocare
    become: true
    become_method: sudo
    ansible.builtin.apt:
    deb: /home/whocare.deb

  • name: copy dat file to /opt/Tanium/TaniumClient
    become: true
    become_method: sudo # need "-K" parameter, which is short form "--ask-become-pass". $ ansible-playbook <1.yaml> -K.
    copy:
    src: /home/whocare.dat
    dest: /opt/whocare.dat

  • name: restart service
    become: true
    become_method: sudo
    service:
    name: whocare
    state: restarted

Top comments (0)