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
2019-09-18 20:24:19 +00:00
register : debian
2021-10-24 09:18:05 +00:00
2023-08-24 13:04:13 +00:00
- name : Detect Rocky
ansible.builtin.raw : cat /etc/os-release|grep rocky||true
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
2022-05-29 15:31:46 +00:00
register : arch
2023-08-24 13:04:13 +00:00
- name : Install python for rocky
ansible.builtin.raw : dnf install python3 --assumeyes
2022-05-29 15:31:46 +00:00
when : rocky.stdout
2023-08-24 13:04:13 +00:00
- name : Install python for debian
2023-08-24 16:35:48 +00:00
ansible.builtin.raw : apt install python3 --assume-yes
2021-08-18 16:11:58 +00:00
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
2022-05-29 15:31:46 +00:00
when : arch.stdout
2021-10-24 09:18:05 +00:00
2023-08-24 13:04:13 +00:00
- name : Add local repo to mirrorlist
become : true
2021-08-18 16:11:58 +00:00
lineinfile :
2021-02-26 17:58:25 +00:00
path : /etc/pacman.d/mirrorlist
line : "Server= {{system_arch_local_mirror}}/$repo/os/$arch"
state : present
insertbefore : BOF
2022-05-29 15:31:46 +00:00
when : system_arch_local_mirror is defined and arch.stdout
2021-02-26 17:58:25 +00:00
2023-08-24 13:03:40 +00:00
- name : Update archlinux-keyring
community.general.pacman :
state : latest
name : archlinux-keyring
become : true
when : arch.stdout
- 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
2023-08-24 13:03:40 +00:00
become : true
2023-08-24 16:35:48 +00:00
register : upgrade_arch
2022-05-29 15:31:46 +00:00
when : arch.stdout
2019-09-18 20:24:19 +00:00
2023-08-24 13:03:40 +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
2023-08-24 13:03:40 +00:00
become : true
2021-08-18 16:11:58 +00:00
when : debian.stdout
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 :
(arch.stdout and (upgrade_arch.changed and upgrade_arch.packages is defined and "linux" in upgrade_arch.packages))
or (debian.stdout 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
2019-09-18 20:24:19 +00:00
package :
2021-08-18 16:10:30 +00:00
state : present
name : zsh
update_cache : true # not required. Whether or not to refresh the master package lists. This can be run as part of a package installation or as a separate step.
2019-09-18 20:24:19 +00:00
2023-08-24 13:04:13 +00:00
- name : Inetutils install
2021-10-23 19:11:53 +00:00
package :
state : present
name : inetutils
2022-05-29 15:31:46 +00:00
when : arch.stdout
2021-10-23 19:11:53 +00:00
2023-08-24 13:04:13 +00:00
- name : Sudoers install
2021-08-18 16:10:30 +00:00
package :
state: present # not required. choices : absent;latest;present. Desired state of the package.
name : sudo # not required. Name or list of names of the packages to install, upgrade, or remove.
2019-09-18 20:24:19 +00:00
2023-08-24 13:04:13 +00:00
- name : Create profil
2018-12-01 19:56:20 +00:00
user :
2022-11-06 18:11:42 +00:00
name : "ansible" # required. Name of the user to create, remove or modify.
2021-08-18 16:11:16 +00:00
create_home : yes # not required. Unless set to C(no), a home directory will be made for the user when the account is created or if the home directory does not exist.,Changed from C(createhome) to C(create_home) in version 2.5.
system : no # not required. When creating an account C(state=present), setting this to C(yes) makes the user a system account. This setting cannot be changed on existing users.
state: present # not required. choices : absent;present. Whether the account should exist or not, taking action if the state is different from what is stated.
ssh_key_file : .ssh/id_rsa # not required. Optionally specify the SSH key filename. If this is a relative filename then it will be relative to the user's home directory.
shell : /bin/bash
2023-08-24 13:04:13 +00:00
- name : Set sudoers right
2018-12-01 20:01:35 +00:00
lineinfile :
2022-11-06 18:11:42 +00:00
dest : "/etc/sudoers.d/ansible"
2021-08-18 16:11:58 +00:00
regexp : "{{ item.regexp }}"
line : "{{ item.line }}"
state : "present"
2018-12-01 20:01:35 +00:00
create : True
2021-08-18 16:11:58 +00:00
owner : "root"
group : "root"
mode : "0440"
2018-12-01 20:01:35 +00:00
validate : 'visudo -cf "%s"'
with_items :
2022-11-06 18:11:42 +00:00
- regexp : '^ansible\s'
line : "ansible ALL = (ALL) NOPASSWD:ALL"
2018-12-01 20:01:35 +00:00
- name : Ensure /etc/sudoers includes /etc/sudoers.d
lineinfile :
2021-08-18 16:11:16 +00:00
dest : "/etc/sudoers"
2018-12-01 20:01:35 +00:00
regexp : '^#includedir\s+/etc/sudoers.d$'
2021-08-18 16:11:16 +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
authorized_key :
2022-11-06 18:11:42 +00:00
user : "ansible"
2020-03-01 20:06:02 +00:00
state : present
2022-11-06 18:11:42 +00:00
key : "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"