Ansible Automation

Hi Gurus,

I am new to ansible automation, kindly suggest me whether i am going in right path.

I Want to automate deployment of apache,mysql-server on multiple Linux hosts.

ansible version i am using ansible 1.5.4
OS: Ubuntu 14.04.5 LTS

below is the Script created for the same

---
- hosts: all
  tasks:
    - name: "Install Softwares Apache,Mysql-server,Php,Php-gd,php5-mysql"
      apt: name={{ item }} update_cache=yes state=latest
      with_items:
      - apache2
      - mysql-server
      - php5-mysql
      - php5
      - php5-gd
    - name: "Restart Apache"
      service: name=apache2 state=restarted
      notify:
      - reload apache2
    - name: "start Mysql"
      service: name=mysql state=started
      notify:
      - start mysql
    - name: "Os Distro with <= 5"
      when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' and ansible_lsb.major_release|int <= 5
      apt: name={{ item }} update_cache=yes state=latest
      with_items:
      - php-devel
      - pecl
      - jason
    - name: "Identify Json Configuration Files"
      stat: path=/etc/php.d/json.ini
      register: JSON_CONFIG
    - name: "Modify File"
      lineinfile: dest=/etc/php.d/json.ini line="# Json Extension"
      lineinfile: dest=/etc/php.d/json.ini line="extension=json.so"
      when: JSON_CONFIG == true
      register: MOD_JSON_FL
    - name: "Restart Apache"
      service: name=apache2 state=restarted
      when: MOD_JSON_FL == true
      notify:
      - reload apache2
  handlers:
    - name: reload apache2
      service: name=apache2 state=reloaded
    - name: start mysql
      service: name=mysql state=started

Regard's
Venkatesh K

Hi, try the playbook against Test machine first so you can see if there is any issues.

Hi Corleone,

Thanks for the Reply, I tried and it was working as per our requirements on Ubuntu.

---
- hosts: linux
  tasks:
    - name: "Install Softwares Apache,Mysql-server,Php,Php-gd,php5-mysql"
      apt: name={{ item }} update_cache=yes state=latest
      with_items:
      - apache2
      - mysql-server
      - python-mysqldb
      - php5-mysql
      - php5-mcrypt
      - php5-curl
      - php5
      - php5-gd
    - name: "Restart Apache"
      service: name=apache2 state=started
      notify:
      - reload apache2
    - name: "start Mysql"
      service: name=mysql state=started
      notify:
      - start mysql
    - name: "Os Distro with <= 5"
      when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' and ansible_lsb.major_release|int <= 5
      apt: name={{ item }} update_cache=yes state=latest
      with_items:
      - php-devel
      - perl
      - jason
    - name: "Modify File jason config file"
      lineinfile:
         dest: /etc/php.d/json.ini
         line: "{{item}}"
      with_items:
      - "# Json Extension"
      - "extension=json.so"
      when: ansible_lsb.major_release|int <= 5
      register: MOD_JSON_FL
    - name: "Restart Apache"
      service: name=apache2 state=restarted
      when: MOD_JSON_FL == true
      notify:
      - reload apache2
    - name: "Create Demo Data Base"
      mysql_db: login_user=root login_password=root name=demo12 state=present collation=utf8_general_ci
    - name: "Create Demo User"
      mysql_user: login_user=root login_password=root name=demo12 password=root priv=*.*:ALL,GRANT host=localhost state=present
    - name: "Restart My Sql Service"
      service: name=mysql state=restarted
    - name: "Download Xibo 1.7.7 Version "
      get_url:
        url: "https://github.com/xibosignage/xibo-cms/archive/1.7.7.tar.gz"
        dest: /var/www/html/xibo_1.7.7.tar.gz
    - name: "Unarchive Xibo Tarball "
      ignore_errors: yes
      command: "{{item}}"
      with_items:
      - tar zxvf /var/www/html/xibo_1.7.7.tar.gz -C /var/www/html/
      - mv /var/www/html/xibo-cms-1.7.7/ /var/www/html/xibo/
    - name: "Change Permissions"
      ignore_errors: yes
      file: path=/var/www/html/xibo/ owner=www-data group=www-data
    - name: "Creating the Media library and Manipulating the Permissions"
      ignore_errors: yes
      file: path=/var/www/html/xibo-library owner=www-data group=www-data mode=0755 state=directory
    - name: "Remove tar dump"
      ignore_errors: yes
      file: path=/var/www/html/xibo_1.7.7.tar.gz state=absent
    - name: "Check Config file /etc/php5/apache2/php.ini"
      stat: path=/etc/php5/apache2/php.ini
      register: PH_Ini_Sts
    - name: "Making Changes to Max Upload File Size,post_max_size,upload_max_size,max_execution_time in /etc/php5/apache2/php.ini"
      replace: dest=/etc/php5/apache2/php.ini
          regexp="{{item.regexp}}"
          replace="{{item.line}}"
      with_items:
      - { regexp: "^(.*)max_input_time(.*)$", line: 'max_input_time = 5000' }
      - { regexp: "^(.*)memory_limit(.*)$", line: 'memory_limit = 1000M' }
      - { regexp: "^(.*)max_execution_time(.*)$", line: 'max_execution_time = 5000' }
      - { regexp: "^(.*)post_max_size(.*)$", line: 'post_max_size = 750M' }
      - { regexp: "^(.*)upload_max_filesize(.*)$", line: 'upload_max_filesize = 750M' }
      when: PH_Ini_Sts == true
    - name: "Adding Localhost entry in /etc/apache2/apache2.conf"
      lineinfile: dest=/etc/apache2/apache2.conf line="ServerName localhost"
    - name: "Run PHPenmode COmmand"
      command: php5enmod mcrypt
    - name: "White Labelling"
      ignore_errors: yes
      copy: src="{{item}}" dest=/var/www/html/xibo/theme/default/img/ backup=yes owner=www-data
      with_items:
      - ~/xibologo.png
      - ~/favicon.ico
    - name: "Replacing Xibo with VENKAT in /var/www/html/xibo/theme/default/config.php"
      replace: dest=/var/www/html/xibo/theme/default/config.php
         regexp="{{item.regexp}}"
         replace="{{item.line}}"
      with_items:
      - { regexp: "^(.*)theme_title(.*)$", line: "              'theme_title' => 'VENKAT Digital Signage'," }
      - { regexp: "^(.*)app_name(.*)$", line: "         'app_name' => 'VENKAT'," }
    - name: "Restart Apache"
      service: name=apache2 state=restarted
  handlers:
    - name: reload apache2
      service: name=apache2 state=reloaded
    - name: start mysql
      service: name=mysql state=started
    - name: FIL_COPY
      command: ls
  #If Proxy needed
  #environment:
  #   http:

Cool, pretty good playbook. I am implementing Ansible in our environment so lets keep posting our notes as someone might find it useful.