Automation with ansible for dba 1.0

I don’t have any knowledge how to automate, I never cared about it, because I was a DBA, now my new colleague is a geeky system administrator and now I see how things are done. Let me introduce:

[oracle@hackbook scripts]$ rpm -qa | grep ansible
ansible-2.1.0.0-1.el7.noarch

I have created 2 VMs to play with them.. they are copies of a template used for my hackbook VM.
-f is for parallel execution, default are 5 parallel processes

  1. Check all hosts
    [root@hackbook ~]# ansible all -m ping
    hack-a1.example.com | SUCCESS => {
        "changed": false,
        "ping": "pong"
    }
    hack-a2.example.com | SUCCESS => {
        "changed": false,
        "ping": "pong"
    }
  2. File transfer
    [root@hackbook ~]# ansible agents -m copy -a "src=/home/oracle/Downloads/workapp.zip dest=/tmp"
    hack-a1.example.com | SUCCESS => {
        "changed": true,
        "checksum": "3ee1dfe5609e1767d50d9758b9f945a92ea9b046",
        "dest": "/tmp/workapp.zip",
        "gid": 0,
        "group": "root",
        "md5sum": "9a01fd1b33b361304c9c3150f64c9232",
        "mode": "0644",
        "owner": "root",
        "secontext": "unconfined_u:object_r:admin_home_t:s0",
        "size": 43338,
        "src": "/root/.ansible/tmp/ansible-tmp-1469011514.56-11092828015532/source",
        "state": "file",
        "uid": 0
    }
    hack-a2.example.com | SUCCESS => {
        "changed": true,
        "checksum": "3ee1dfe5609e1767d50d9758b9f945a92ea9b046",
        "dest": "/tmp/workapp.zip",
        "gid": 0,
        "group": "root",
        "md5sum": "9a01fd1b33b361304c9c3150f64c9232",
        "mode": "0644",
        "owner": "root",
        "secontext": "unconfined_u:object_r:admin_home_t:s0",
        "size": 43338,
        "src": "/root/.ansible/tmp/ansible-tmp-1469011514.57-237433087750369/source",
        "state": "file",
        "uid": 0
    }
  3. Shell execution
    [root@hackbook ~]# ansible all -m shell -a "chown oracle:dba /tmp/work*" -f 1
    hack-a1.example.com | SUCCESS | rc=0 >>
    
    
    hack-a2.example.com | SUCCESS | rc=0 >>
    
    
    [root@hackbook ~]# ansible all -m shell -a "ls -l /tmp/work*" -f 1
    hack-a1.example.com | SUCCESS | rc=0 >>
    -rw-r--r--. 1 oracle dba 43338 Jul 20 12:47 /tmp/workapp.zip
    
    hack-a2.example.com | SUCCESS | rc=0 >>
    -rw-r--r--. 1 oracle dba 43338 Jul 20 12:47 /tmp/workapp.zip
    
    
  4. Files
    [root@hackbook ~]# ansible all -m file -a "dest=/tmp/oracle state=directory"
    hack-a2.example.com | SUCCESS => {
        "changed": true,
        "gid": 0,
        "group": "root",
        "mode": "0755",
        "owner": "root",
        "path": "/tmp/oracle",
        "secontext": "unconfined_u:object_r:user_tmp_t:s0",
        "size": 6,
        "state": "directory",
        "uid": 0
    }
    hack-a1.example.com | SUCCESS => {
        "changed": true,
        "gid": 0,
        "group": "root",
        "mode": "0755",
        "owner": "root",
        "path": "/tmp/oracle",
        "secontext": "unconfined_u:object_r:user_tmp_t:s0",
        "size": 6,
        "state": "directory",
        "uid": 0
    }
    [root@hackbook ~]# ansible all -m file -a "dest=/tmp/oracle state=absent"
    hack-a2.example.com | SUCCESS => {
        "changed": true,
        "path": "/tmp/oracle",
        "state": "absent"
    }
    hack-a1.example.com | SUCCESS => {
        "changed": true,
        "path": "/tmp/oracle",
        "state": "absent"
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s