ansible_bootstrap/tasks/main.yml

145 lines
3.5 KiB
YAML
Raw Normal View History

2018-12-01 19:56:20 +00:00
---
# tasks file for ansible_bootstrap
2023-08-24 13:04:13 +00:00
- name: Detect debian
ansible.builtin.raw: cat /etc/os-release|grep Debian||true
2023-08-25 07:01:09 +00:00
changed_when: false
2019-09-18 20:24:19 +00:00
register: debian
2023-08-24 13:04:13 +00:00
- name: Detect Rocky
ansible.builtin.raw: cat /etc/os-release|grep rocky||true
2023-08-25 07:01:09 +00:00
changed_when: false
2022-05-29 15:31:46 +00:00
register: rocky
2023-08-24 13:04:13 +00:00
- name: Detect arch
ansible.builtin.raw: cat /etc/os-release|grep Arch||true
2023-08-25 07:01:09 +00:00
changed_when: false
2022-05-29 15:31:46 +00:00
register: arch
2023-10-24 20:45:58 +00:00
#- name: Install python for rocky
# ansible.builtin.raw: dnf install python3 --assumeyes
#changed_when: false
#when: rocky.stdout
2022-05-29 15:31:46 +00:00
2023-10-24 20:45:58 +00:00
#- name: Install python for debian
# ansible.builtin.raw: apt install python3 --assume-yes
#changed_when: false
#when: debian.stdout
2019-09-18 20:24:19 +00:00
2023-08-24 13:04:13 +00:00
- name: Install python on arch
ansible.builtin.raw: pacman -Sy python --noconfirm
2023-08-25 07:01:09 +00:00
changed_when: false
2023-10-24 20:45:58 +00:00
when: arch.stdout is match(".*Arch Linux.*")
2023-08-24 13:04:13 +00:00
- name: Add local repo to mirrorlist
become: true
2023-08-25 07:01:09 +00:00
ansible.builtin.lineinfile:
2021-02-26 17:58:25 +00:00
path: /etc/pacman.d/mirrorlist
2023-08-25 07:01:09 +00:00
line: 'Server= {{ system_arch_local_mirror }}/$repo/os/$arch'
2021-02-26 17:58:25 +00:00
state: present
insertbefore: BOF
2023-10-24 20:45:58 +00:00
when: system_arch_local_mirror is defined and arch.stdout is match(".*Arch Linux.*")
2021-02-26 17:58:25 +00:00
- name: Update archlinux-keyring
community.general.pacman:
state: latest
name: archlinux-keyring
become: true
2023-10-24 20:45:58 +00:00
when: arch.stdout is match(".*Arch Linux.*")
- name: Upgrade system for arch
2023-08-25 07:00:38 +00:00
community.general.pacman:
state: latest
upgrade: true
force: true
2021-08-18 16:11:58 +00:00
update_cache: true
become: true
2023-08-24 16:35:48 +00:00
register: upgrade_arch
2023-10-24 20:45:58 +00:00
when: arch.stdout is match(".*Arch Linux.*")
2019-09-18 20:24:19 +00:00
- name: Upgrade system for debian
2023-08-25 07:00:38 +00:00
ansible.builtin.apt:
update_cache: true
only_upgrade: true
upgrade: full
become: true
2023-10-24 20:45:58 +00:00
when: debian.stdout is match(".*Debian.*")
2023-08-24 16:35:48 +00:00
register: upgrade_debian
2019-09-18 20:24:19 +00:00
2019-04-15 18:14:02 +00:00
- name: Reboot updates to apply
2023-08-25 07:00:38 +00:00
ansible.builtin.reboot:
2021-08-18 16:11:58 +00:00
reboot_timeout: 3600
2023-08-25 07:00:38 +00:00
when:
2023-10-24 20:45:58 +00:00
(arch.stdout is match(".*Arch Linux.*") and (upgrade_arch.changed and upgrade_arch.packages is defined and "linux" in upgrade_arch.packages))
or (debian.stdout is match(".*Debian.*") and upgrade_debian.changed)
2023-08-24 13:04:13 +00:00
become: true
2019-04-15 18:14:02 +00:00
2022-10-30 17:11:47 +00:00
- name: Collect only selected facts
ansible.builtin.setup:
filter:
- 'ansible_distribution'
2022-10-30 17:14:42 +00:00
- 'ansible_os_family'
2022-10-30 17:11:47 +00:00
2023-08-24 13:04:13 +00:00
- name: Zsh install
2023-08-25 07:01:09 +00:00
ansible.builtin.package:
2021-08-18 16:10:30 +00:00
state: present
name: zsh
2023-08-25 07:01:09 +00:00
update_cache: true
2019-09-18 20:24:19 +00:00
2023-08-24 13:04:13 +00:00
- name: Inetutils install
2023-08-25 07:01:09 +00:00
ansible.builtin.package:
2021-10-23 19:11:53 +00:00
state: present
name: inetutils
2023-10-24 20:45:58 +00:00
when: ansible_os_family == "Archlinux"
2021-10-23 19:11:53 +00:00
- name: Iptable install
ansible.builtin.package:
state: present
name: iptables
when: ansible_os_family == "Debian"
2023-08-24 13:04:13 +00:00
- name: Sudoers install
2023-08-25 07:01:09 +00:00
ansible.builtin.package:
state: present
name: sudo
2019-09-18 20:24:19 +00:00
2023-08-24 13:04:13 +00:00
- name: Create profil
2023-08-25 07:01:09 +00:00
ansible.builtin.user:
name: 'ansible'
create_home: true
system: false
state: present
ssh_key_file: .ssh/id_rsa
2021-08-18 16:11:16 +00:00
shell: /bin/bash
2023-08-24 13:04:13 +00:00
- name: Set sudoers right
2023-08-25 07:01:09 +00:00
ansible.builtin.lineinfile:
dest: '/etc/sudoers.d/ansible'
regexp: '{{ item.regexp }}'
line: '{{ item.line }}'
state: 'present'
create: true
owner: 'root'
group: 'root'
mode: '0440'
2018-12-01 20:01:35 +00:00
validate: 'visudo -cf "%s"'
with_items:
- regexp: '^ansible\s'
2023-08-25 07:01:09 +00:00
line: 'ansible ALL = (ALL) NOPASSWD:ALL'
2018-12-01 20:01:35 +00:00
- name: Ensure /etc/sudoers includes /etc/sudoers.d
2023-08-25 07:01:09 +00:00
ansible.builtin.lineinfile:
dest: '/etc/sudoers'
2018-12-01 20:01:35 +00:00
regexp: '^#includedir\s+/etc/sudoers.d$'
2023-08-25 07:01:09 +00:00
line: '#includedir /etc/sudoers.d'
state: 'present'
2018-12-01 20:01:35 +00:00
validate: 'visudo -cf "%s"'
2018-12-02 20:02:00 +00:00
2020-03-01 20:06:02 +00:00
- name: Set authorized key taken from file
2023-08-25 07:01:09 +00:00
ansible.posix.authorized_key:
user: 'ansible'
2020-03-01 20:06:02 +00:00
state: present
key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"