Install Ansible

Install Ansible on MacOS
——————————

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py --user
$ python -m pip install --user ansible
$ python -m pip install --user paramiko
--- python 2.7 ---
$ sudo python get-pip.py
$ sudo python -m pip install ansible
--- python 3.x ---
$ sudo python3 get-pip.py
$ sudo python3 -m pip install ansible

Installing Ansible on Ubuntu
———————————

$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible
$ sudo apt-get install sshpass

Installing Ansible on CentOS
———————————

$ sudo yum install epel-release
$ sudo yum install ansible

Configuration
—————-

$ vi ~/.ansible/hosts
[mikrotik]
R21 ansible_host=192.168.21.21

[mikrotik:vars]
ansible_user = agink
ansible_password = isikanPasswordAnda
ansible_port = 2121
ansible_connection = network_cli
ansible_network_os = routeros
$ vi ~/.ansible.cfg
[defaults]
inventory = $HOME/.ansible/hosts
remote_tmp = $HOME/.ansible/tmp/ansible-${USER}/tmp
local_tmp = $HOME/.ansible/tmp/ansible-${USER}/tmp
host_key_checking = False
timeout = 15
log_path = $HOME/.ansible/ansible.log

Testing
———

$ ansible mikrotik -m ping
R21 | SUCCESS => {
"changed": false,
"ping": "pong"
}

Ansible Playbook
——————–

$ vi mikrotik.yml
---
- name: AGINK - MikroTik Automation
  hosts: mikrotik

  vars:
  
  tasks:
     - name: Disable Service Jarang Terpakai
       routeros_command:
         commands: /ip service disable {{item}}
       with_items:
         - api
         - api-ssl
         - ftp
         - telnet
         - www
         - www-ssl
$ ansible-playbook mikrotik.yml --syntax-check
playbook: mikrotik.yml
$ ansible-playbook mikrotik.yml
PLAY [AGINK - MikroTik Automation] ************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************
ok: [R21]

TASK [Disable Service Jarang Terpakai] ********************************************************************************************************
ok: [R21] => (item=api)
ok: [R21] => (item=api-ssl)
ok: [R21] => (item=ftp)
ok: [R21] => (item=telnet)
ok: [R21] => (item=www)
ok: [R21] => (item=www-ssl)

PLAY RECAP ************************************************************************************************************************************
R21 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0


Posted

in

Tags: