Created main system configuration playbook
This commit is contained in:
69
configure@vps.yml
Normal file
69
configure@vps.yml
Normal file
@@ -0,0 +1,69 @@
|
||||
---
|
||||
- name: Configure virtual private servers
|
||||
hosts: vps
|
||||
gather_facts: yes
|
||||
vars:
|
||||
# # below is just to remind you to use '-u' instead
|
||||
# ansible_user: "{{ root_auths[0].username }}"
|
||||
# # below is just to remind you to use '--ask-pass' instead
|
||||
# ansible_password: "{{ root_auths[0].password }}"
|
||||
FAMILY: "{{ ansible_facts['os_family'] }}"
|
||||
CURRENT_HOST_IP4: "{{ hostvars[inventory_hostname]['ansible_facts']['ansible_default_ipv4']['address'] }}"
|
||||
CURRENT_HOST_IP6: "{{ hostvars[inventory_hostname]['ansible_facts']['ansible_default_ipv6']['address'] }}"
|
||||
FQDN: "{{ domain_name | default(inventory_hostname, true) }}"
|
||||
|
||||
pre_tasks:
|
||||
- name: Set timezone
|
||||
community.general.timezone:
|
||||
name: "{{ tzone }}"
|
||||
register: timezone_set
|
||||
tags: ['baseconf', 'timezone_setting']
|
||||
- name: Set hostname
|
||||
hostname:
|
||||
name: "{{ hname }}"
|
||||
use: "{{ FAMILY.lower() }}"
|
||||
register: hostname_set
|
||||
tags: ['baseconf', 'hostname_initialization']
|
||||
- name: Add remote host alias to hosts file
|
||||
lineinfile:
|
||||
path: /etc/hosts
|
||||
search_string: "127.0.1.1"
|
||||
line: "127.0.1.1 {{ hname }}"
|
||||
state: present
|
||||
create: yes
|
||||
register: hosts_updated
|
||||
tags: ['baseconf', 'hostsfile_update']
|
||||
- name: Add remote host public address aliases to hosts file
|
||||
lineinfile:
|
||||
path: /etc/hosts
|
||||
search_string: "{{ CURRENT_HOST_IP4 }}"
|
||||
line: "{{ CURRENT_HOST_IP4 }} {{ FQDN }} {{ hname }}"
|
||||
state: present
|
||||
create: yes
|
||||
register: hosts_updated
|
||||
when: CURRENT_HOST_IP4 is defined
|
||||
tags: ['baseconf', 'hostsfile_update']
|
||||
- name: Add remote host public address aliases to hosts file
|
||||
lineinfile:
|
||||
path: /etc/hosts
|
||||
search_string: "{{ CURRENT_HOST_IP6 }}"
|
||||
line: "{{ CURRENT_HOST_IP6 }} {{ FQDN }} {{ hname }}"
|
||||
state: present
|
||||
create: yes
|
||||
register: hosts_updated
|
||||
when: CURRENT_HOST_IP6 is defined
|
||||
tags: ['baseconf', 'hostsfile_update']
|
||||
|
||||
tasks:
|
||||
- name: Do a system upgrade
|
||||
include_role:
|
||||
name: bootstrap
|
||||
defaults_from: general.yml
|
||||
tasks_from: "upgrade@{{ FAMILY }}.yml"
|
||||
vars:
|
||||
upgrade_type: dist
|
||||
register: system_initialized
|
||||
tags: ['default', 'initial_system_upgrade']
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user