diff --git a/ansible.cfg b/ansible.cfg index 60098ac..0125b60 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,5 +1,14 @@ [defaults] -inventory = hosts +# hosts file path +inventory = hosts +# number of hosts executed in parallel +forks = 20 +# show execution time +callbacks_enabled = timer, profile_tasks, profile_roles +# reduce number of parallel ssh connections to one host +pipelining = True +[ssh_connection] +ssh_args = -o ControlMaster=auto -o ControlPersist=40s # (boolean) By default Ansible will issue a warning when received from a task action (module or action plugin) # These warnings can be silenced by adjusting this setting to False. ;action_warnings=True diff --git a/hosts b/hosts index 4700fb2..b7607c5 100644 --- a/hosts +++ b/hosts @@ -1,23 +1,26 @@ [desktop] [headless] -server[1:7]_oracle +server[1:7] +openmediavault [oracleServer] -server[1:7]_oracle +server[1:7] [home] [ubuntu] -server[1:7]_oracle +server[1:7] [arm64] -server[2:6:2]_oracle -server7_oracle +server[2:6:2] +server7 [amd64] -server[1:5:2]_oracle +server[1:5:2] +openmediavault [prod] -server1_oracle -server2_oracle +server1 +server2 +openmediavault diff --git a/install-dockerCompose.yml b/install_dockerCompose.yml similarity index 90% rename from install-dockerCompose.yml rename to install_dockerCompose.yml index 9e9596a..57c547b 100644 --- a/install-dockerCompose.yml +++ b/install_dockerCompose.yml @@ -8,6 +8,6 @@ include_role: name: force_limitArg - - name: Reboot if required + - name: Install Docker Compose include_role: name: install_dockerCompose diff --git a/local.yml b/local.yml deleted file mode 100644 index 43fbc26..0000000 --- a/local.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- hosts: localhost - tags: - become: - pre_tasks: - - - -- hosts: - tags: - become: - roles: diff --git a/oci-kali.yml b/oci_kali.yml similarity index 100% rename from oci-kali.yml rename to oci_kali.yml diff --git a/package_upgrade.yml b/package_upgrade.yml index 4270b37..029c23b 100644 --- a/package_upgrade.yml +++ b/package_upgrade.yml @@ -1,10 +1,9 @@ --- -- name: update apt-cache and upgrade +- name: Update apt-cache and upgrade hosts: oracleServer tasks: - - name: upgrade packages + - name: Upgrade packages become: true - package: - update_cache: yes - upgrade: 'yes' - + ansible.builtin.package: + update_cache: true + upgrade: true diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..ec2fb95 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,19 @@ +--- +roles: + - name: jan_matthis.git_dotfiles + - name: geerlingguy.dotfiles + version: "1.2.1" + - name: geerlingguy.docker + version: "6.1.0" + - name: geerlingguy.git + version: "3.1.0" + - name: geerlingguy.pip + version: "2.2.0" + - name: geerlingguy.nginx + version: "3.1.4" + +collections: + - name: oracle.oci + version: "4.18.0" + - name: community.docker + version: "3.4.3" diff --git a/roles/install_dockerCompose/tasks/main.yml b/roles/install_dockerCompose/tasks/main.yml index e3f123c..374d265 100644 --- a/roles/install_dockerCompose/tasks/main.yml +++ b/roles/install_dockerCompose/tasks/main.yml @@ -7,7 +7,7 @@ - gnupg - lsb-release state: latest - update_cache: yes + update_cache: true - name: Add Docker GPG Key become: true @@ -19,13 +19,13 @@ - name: Add Docker Repository become: true apt_repository: - repo: "deb [arch={{ arch }}] https://download.docker.com/linux/{{ansible_distribution|lower}} {{ansible_distribution_release}} stable" + repo: "deb [arch={{ arch }}] https://download.docker.com/linux/{{ansible_distribution|lower}} {{ansible_distribution_release}} {{release_branch_docker}}" state: present - name: Install Docker packages become: true apt: - update_cache: yes + update_cache: true pkg: - docker-ce - docker-ce-cli @@ -39,7 +39,7 @@ name: "{{ ansible_user_id }}" groups: - docker - append: yes + append: true - name: Create docker folder in home directory file: diff --git a/roles/install_dotfiles/defaults/main.yml b/roles/install_dotfiles/defaults/main.yml new file mode 100644 index 0000000..1255a1f --- /dev/null +++ b/roles/install_dotfiles/defaults/main.yml @@ -0,0 +1,3 @@ +dotfiles_repo_source: "git@github.com:eneller/.dotfiles" +dotfiles_repo_commit: "headless" +dotfiles_repo_destination: ".dotfiles" \ No newline at end of file diff --git a/roles/install_dotfiles/tasks/main.yml b/roles/install_dotfiles/tasks/main.yml new file mode 100644 index 0000000..9c0c5ff --- /dev/null +++ b/roles/install_dotfiles/tasks/main.yml @@ -0,0 +1,29 @@ +- name: Check for existing dotfiles repository + ansible.builtin.stat: + path: "{{ dotfiles_repo_destination }}HEAD" + register: dotfiles_repo_head + changed_when: false + +- name: Clone into /tmp + ansible.builtin.git: + dest: /tmp/dotfiles + repo: "{{ dotfiles_repo_source }}" + version: "{{ dotfiles_repo_commit }}" + when: not dotfiles_repo_head.stat.exists + +- name: Back up existing dotfiles + ansible.builtin.shell: + chdir: /tmp/dotfiles + cmd: | + git ls-files | while read -r line; do + mv $HOME/$line $HOME/$line.bak + done + # when: # TODO only if bare repo doesnt already exist + when: not dotfiles_repo_head.stat.exists +- name: Initialize dotfiles repository in user home + ansible.builtin.git: + bare: true + update: true + dest: "{{ ansible_user_directory }}/{{ dotfiles_repo_destination }}" + repo: "{{ dotfiles_repo_source }}" + version: "{{ dotfiles_repo_commit }}" diff --git a/ssh_updateKey.yml b/ssh_updateKey.yml index 93c79a8..04205e5 100644 --- a/ssh_updateKey.yml +++ b/ssh_updateKey.yml @@ -1,13 +1,35 @@ --- # https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html#examples -- name: update apt-cache and upgrade +- name: update ssh key and login permissions + strategy: free # dont wait for other hosts when executing hosts: oracleServer tasks: - - name: upgrade packages + + - name: Add ssh key become: true + async: 120 # Maximum execution time + poll: 05 # polling interval in seconds ansible.posix.authorized_key: user: "{{ ansible_user_id }}" exclusive: true state: present key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}" + - name: sshd configuration file update + blockinfile: + path: /etc/ssh/sshd_config + insertbefore: BOF # Beginning of the file + marker: "# {mark} ANSIBLE MANAGED BLOCK BY LINUX-ADMIN" + block: | + PermitRootLogin no + PubkeyAuthentication yes + AuthorizedKeysFile .ssh/authorized_keys + PasswordAuthentication no + backup: true + validate: /usr/sbin/sshd -T -f %s + + - name: Restart SSHD + service: + name: sshd + state: restarted +