playbook-full_apache_mariadb
# ansible-playbook -i inventory playbook-full_apache.yml
---
- hosts: all
become: yes
tasks:
#- debug: var=ansible_all_ipv4_addresses
#- debug: var=ansible_default_ipv4.address
- name: Show host's ip adress
debug:
msg: "{{ ansible_ssh_host }}"
- name: Show host's ip last bit
debug:
msg: "{{ ansible_default_ipv4.address.split('.')[3] }}"
- name: Install mariadb-server
ansible.builtin.package:
name: mariadb-server
state: present
- name: Restart service mariadb-server, in all cases
ansible.builtin.service:
name: mariadb
state: started
- name: Install apache2
ansible.builtin.package:
name: apache2
state: present
- name: Ensure the default Apache port is 8080
ansible.builtin.lineinfile:
path: /etc/apache2/ports.conf
regexp: '^Listen '
insertafter: '^#Listen '
line: Listen 8080
- name: Restart service httpd, in all cases
ansible.builtin.service:
name: apache2
state: restarted
- name: Hostname changer
ansible.builtin.hostname:
#name: "{{ ansible_hostname}}{{ansible_default_ipv4.address.split('.')[3] }}"
name: tbrdebian{{ ansible_default_ipv4.address.split('.')[3] }}
- name: Change hostname in hostfile
ansible.builtin.lineinfile:
path: /etc/hosts
regexp: '^127.0.1.1'
insertafter: '^#127.0.1.1'
line: 127.0.1.1 {{ ansible_hostname }}
- name: Change hostname in hostfile
ansible.builtin.lineinfile:
path: /etc/hosts
regexp: '^{{ansible_default_ipv4.address}}'
insertafter: '^#{{ansible_default_ipv4.address}}'
line: "{{ansible_default_ipv4.address}} {{ ansible_hostname }}"
- name: What is my ansible_hostname
debug: var={{ansible_hostname}}
#- name: What is my inventory_hostname
#debug: var={{inventory_hostname}}