Advertisement
D0cEvil

Ansible - LAMP deploy

Dec 27th, 2022
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.79 KB | Software | 0 0
  1. - hosts: testservers
  2.   tasks:
  3.  
  4.   #### SYSTEM UPDATE ####
  5.  
  6.   - name: System Update
  7.     yum: name=* state=latest
  8.     when: ansible_distribution == "CentOS"
  9.  
  10.   - name: Disable SELinux
  11.     selinux: state=disabled
  12.     when: ansible_distribution == "CentOS"
  13.  
  14.   - name: Installing epel-rep
  15.     yum: pkg=epel-release state=latest
  16.     when: ansible_distribution == "CentOS"
  17.  
  18.   - name: Reboot server
  19.     shell: sleep 3 && /sbin/shutdown -r "Ansible system reboot"
  20.     async: 1
  21.     poll: 0
  22.  
  23.   - name: Waiting for SSH connection
  24.     local_action: wait_for host={{ inventory_hostname }} port=22 delay=20 connect_timeout=200
  25.     become: false
  26.     delegate_to: localhost
  27.  
  28. #### Software Installation ####
  29.  
  30.   - name: Installation Utils
  31.     yum: pkg={{ item }}
  32.     with_items:
  33.      - wget
  34.       - mc
  35.       - nano
  36.     when: ansible_distribution == "CentOS"
  37.  
  38.   - name: Installation Apache
  39.     yum: pkg=httpd state=present
  40.     when: ansible_distribution == "CentOS"
  41.  
  42.   - name: Enable Apache on System Boot
  43.     service: name=httpd enabled=yes
  44.     when: ansible_distribution == "CentOS"
  45.  
  46.   - name: Installation PHP mods
  47.     yum: pkg={{ item }} state=present
  48.     with_items:
  49.     - php
  50.      - php-gd
  51.      - php-mysql
  52.      - php-devel
  53.     when: ansible_distribution == "CentOS"
  54.  
  55.   - name: Installation MariaDB
  56.     yum: pkg=mariadb-server state=present
  57.     when: ansible_distribution == "CentOS"
  58.  
  59.   - name: Enable MariaDB on System Boot
  60.     service: name=mariadb enabled=yes
  61.     when: ansible_distribution == "CentOS"
  62.  
  63.   - name: Installation Pyton Mysql module
  64.     yum: pkg=MySQL-python state=present
  65.     when: ansible_distribution == "CentOS"
  66.  
  67.   - name: Installation PHPmyAdmin
  68.     yum: pkg=phpMyAdmin state=present
  69.     when: ansible_distribution == "CentOS"
  70.  
  71.   - name: Service Mariadb Start
  72.     service: name=mariadb state=started
  73.     when: ansible_distribution == "CentOS"
  74.  
  75.   - name: Service Apache Start
  76.     service: name=httpd state=started
  77.     when: ansible_distribution == "CentOS"
  78.  
  79. ## Configuring MariaDB ##
  80.  
  81.   - name: Set root Password
  82.     mysql_user: user=root password=P@ssw0rd host=localhost
  83.     when: ansible_distribution == "CentOS"
  84.  
  85. #  - name: Reload privilege tables
  86. #    command: mysql -u root -p P@ssw0rd -ne "{{ item }}"
  87. #    with_items:
  88. #       - FLUSH PRIVILEGES
  89. #    when: ansible_distribution == "CentOS"
  90.  
  91.   - name: Create MySQL database
  92.     mysql_db: name=wordpress login_user=root login_password=P@ssw0rd state=present
  93.     when: ansible_distribution == "CentOS"
  94.  
  95.   - name: Create MySQL user
  96.     mysql_user: login_user=root login_password=P@ssw0rd name=wpuser password=P@ssw0rd priv=*.*:ALL
  97.     when: ansible_distribution == "CentOS"
  98.  
  99. ## WordPress ##
  100.  
  101.   - name: DownLoad LAST version WordPress
  102.     get_url: url=https://wordpress.org/latest.tar.gz dest=/tmp/wordpress.tar.gz validate_certs=no
  103.     when: ansible_distribution == "CentOS"
  104.  
  105.   - name: Extract WordPress
  106.     unarchive: src=/tmp/wordpress.tar.gz dest=/var/www/html copy=no
  107.     when: ansible_distribution == "CentOS"
  108.  
  109. #### Firewall Config ####
  110.  
  111.   - name: Add HTTP service
  112.     command: firewall-cmd --add-service=http --permanent
  113.     when: ansible_distribution == "CentOS"
  114.  
  115.   - name: Add HTTPs service
  116.     command: firewall-cmd --add-service=https --permanent
  117.     when: ansible_distribution == "CentOS"
  118.  
  119.   - name: Add MySQL service
  120.     command: firewall-cmd --add-port=3306/tcp --permanent
  121.     when: ansible_distribution == "CentOS"
  122.  
  123.   - name: Restarting firewall
  124.     command: firewall-cmd --reload
  125.     when: ansible_distribution == "CentOS"  
  126.  
  127. #### Services ####
  128.  
  129.   - name: MariaDB restart
  130.     service: name=mariadb state=restarted
  131.     when: ansible_distribution == "CentOS"
  132.  
  133.   - name: Apache restart
  134.     service: name=httpd state=restarted
  135.     when: ansible_distribution == "CentOS"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement