diff --git a/Ansible/ansible.cfg b/Ansible/ansible.cfg new file mode 100644 index 0000000..1f7181c --- /dev/null +++ b/Ansible/ansible.cfg @@ -0,0 +1,16 @@ +[defaults] +bin_ansible_callbacks = True +callbacks_enabled = ansible.posix.profile_tasks, ansible.posix.timer +remote_user = eryn +roles_path = roles +stdout_callback = community.general.yaml + +[connection] +pipelining = true + +[ssh_connection] +ssh_args = -o ControlMaster=auto -o ControlPersist=60s + +[vault] +username = ansible-infrastructure-vault +keyname = default diff --git a/Ansible/roles/dotfiles/handlers/main.yml b/Ansible/roles/dotfiles/handlers/main.yml new file mode 100644 index 0000000..dfc89e5 --- /dev/null +++ b/Ansible/roles/dotfiles/handlers/main.yml @@ -0,0 +1,4 @@ +--- +- name: Rediscover package manager + ansible.builtin.setup: + gather_subset: pkg_mgr diff --git a/Ansible/roles/dotfiles/tasks/darwin/bootstrap.yml b/Ansible/roles/dotfiles/tasks/darwin/bootstrap.yml new file mode 100644 index 0000000..0474ec1 --- /dev/null +++ b/Ansible/roles/dotfiles/tasks/darwin/bootstrap.yml @@ -0,0 +1,3 @@ +--- +- name: (macOS) Configure homebrew + ansible.builtin.include_tasks: homebrew.yml diff --git a/Ansible/roles/dotfiles/tasks/darwin/homebrew.yml b/Ansible/roles/dotfiles/tasks/darwin/homebrew.yml new file mode 100644 index 0000000..2ac20c6 --- /dev/null +++ b/Ansible/roles/dotfiles/tasks/darwin/homebrew.yml @@ -0,0 +1,37 @@ +--- +- name: (macOS | homebrew) Does the brew command exist? + ansible.builtin.stat: + path: /opt/homebrew/bin/brew + register: _dotfiles_homebrew_brew + +- name: (macOS | homebrew) Install Homebrew + when: not _dotfiles_homebrew_brew.stat.exists + block: + - name: (macOS | homebrew) Create temporary file for install script + ansible.builtin.tempfile: + state: file + prefix: homebrew-install + register: _dotfiles_homebrew_install_script + + - name: (macOS | homebrew) Set up homebrew + block: + - name: (macOS | homebrew) Fetch install script + ansible.builtin.get_url: + url: https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh + dest: "{{ _dotfiles_homebrew_install_script.path }}" + mode: "0644" + + - name: (macOS | homebrew) Run install script + ansible.builtin.command: + cmd: bash {{ _dotfiles_homebrew_install_script.path }} + environment: + NONINTERACTIVE: 1 + + - name: (macOS | homebrew) Gather package manager facts + ansible.builtin.setup: + gather_subset: pkg_mgr + always: + - name: (macOS | homebrew) Remove temporary install script + ansible.builtin.file: + path: "{{ _dotfiles_homebrew_install_script.path }}" + state: absent diff --git a/Ansible/roles/dotfiles/tasks/dotfiles.yml b/Ansible/roles/dotfiles/tasks/dotfiles.yml new file mode 100644 index 0000000..389ab23 --- /dev/null +++ b/Ansible/roles/dotfiles/tasks/dotfiles.yml @@ -0,0 +1,28 @@ +--- +- name: (dotfiles) ZSH + ansible.builtin.include_tasks: zsh.yml + tags: [ always, dotfiles_shell, dotfiles_zsh ] + +- name: (dotfiles) Vim + ansible.builtin.include_tasks: vim.yml + tags: [ always, dotfiles_vim ] + +- name: (dotfiles) Emacs + ansible.builtin.include_tasks: emacs.yml + tags: dotfiles_emacs + +- name: (dotfiles) Git + ansible.builtin.include_tasks: git.yml + tags: [ always, dotfiles_git ] + +- name: (dotfiles) Mutt + ansible.builtin.include_tasks: mutt.yml + tags: dotfiles_mutt + +- name: (dotfiles) Shell utilities + ansible.builtin.include_tasks: shell_utilities.yml + tags: dotfiles_shell + +- name: (dotfiles) Nethack + ansible.builtin.include_tasks: nethack.yml + tags: dotfiles_nethack diff --git a/Ansible/roles/dotfiles/tasks/main.yml b/Ansible/roles/dotfiles/tasks/main.yml index e0d319a..91fc42c 100644 --- a/Ansible/roles/dotfiles/tasks/main.yml +++ b/Ansible/roles/dotfiles/tasks/main.yml @@ -1,26 +1,17 @@ --- -- name: ZSH - ansible.builtin.include_tasks: zsh.yml - tags: dotfiles_zsh +- name: Bootstrap system + ansible.builtin.include_tasks: "{{ ansible_facts.os_family | lower }}/bootstrap.yml" -- name: Vim - ansible.builtin.include_tasks: vim.yml - tags: dotfiles_vim +#- name: Install packages +# ansible.builtin.include_tasks: packages.yml -- name: Emacs - ansible.builtin.include_tasks: emacs.yml - tags: dotfiles_emacs - -- name: Git - ansible.builtin.include_tasks: git.yml - tags: dotfiles_git - -- name: Mutt - ansible.builtin.include_tasks: mutt.yml - tags: dotfiles_mutt - -- name: Shell utilities - ansible.builtin.include_tasks: shell_utilities.yml - -- name: Nethack - ansible.builtin.include_tasks: nethack.yml +- name: Link dotfiles + ansible.builtin.include_tasks: dotfiles.yml + tags: + - dotfiles_git + - dotfiles_mutt + - dotfiles_neovim + - dotfiles_nethack + - dotfiles_shell + - dotfiles_vim + - dotfiles_zsh diff --git a/Ansible/roles/dotfiles/tasks/nethack.yml b/Ansible/roles/dotfiles/tasks/nethack.yml index 485e20c..d6e8951 100644 --- a/Ansible/roles/dotfiles/tasks/nethack.yml +++ b/Ansible/roles/dotfiles/tasks/nethack.yml @@ -1,4 +1,12 @@ --- +- name: (nethack) Install nethack package + ansible.builtin.package: + name: nethack + state: present + when: + - dotfiles_install_packages is defined + - "'nethack' in dotfiles_install_packages" + - name: (nethack) Link nethackrc ansible.builtin.file: path: ~/.nethackrc diff --git a/Ansible/roles/dotfiles/tasks/packages.yml b/Ansible/roles/dotfiles/tasks/packages.yml new file mode 100644 index 0000000..0642dc4 --- /dev/null +++ b/Ansible/roles/dotfiles/tasks/packages.yml @@ -0,0 +1,13 @@ +--- +- name: Install packages + become: "{{ _dotfiles_requires_become[ansible_facts.pkg_mgr] | default(true) }}" + vars: + package_names: _dotfiles_package_names[ansible_facts.pkg_mgr] + ansible.builtin.package: + name: > + {{ + package_names[package] | default(package) + for package + in (_dotfiles_core_packages + dotfiles_install_packages) + }} + state: present diff --git a/Ansible/roles/dotfiles/tasks/vim.yml b/Ansible/roles/dotfiles/tasks/vim.yml index 94c6321..e3ff49b 100644 --- a/Ansible/roles/dotfiles/tasks/vim.yml +++ b/Ansible/roles/dotfiles/tasks/vim.yml @@ -7,11 +7,13 @@ force: true - name: (neovim) Create standard config directory + tags: dotfiles_neovim ansible.builtin.file: path: ~/.config state: directory - name: (neovim) Link config + tags: dotfiles_neovim ansible.builtin.file: path: ~/.config/nvim src: "{{ role_path }}/files/neovim" @@ -19,6 +21,7 @@ force: true - name: (neovim) Create .local directories + tags: dotfiles_neovim ansible.builtin.file: path: "{{ item }}" state: directory diff --git a/Ansible/roles/dotfiles/tasks/zsh.yml b/Ansible/roles/dotfiles/tasks/zsh.yml index ef7dd22..c0b8570 100644 --- a/Ansible/roles/dotfiles/tasks/zsh.yml +++ b/Ansible/roles/dotfiles/tasks/zsh.yml @@ -1,31 +1,45 @@ --- -- name: (zsh) Link startup files - ansible.builtin.file: - path: ~/.{{ item }} - src: "{{ role_path }}/files/zsh/{{ item }}" - state: link - force: true - loop: - - zshenv - - zshrc - - zprofile +- name: (zsh) Find zsh binary + ansible.builtin.command: + cmd: sh -c 'which zsh' + register: _dotfiles_which_zsh -- name: (zsh) Create zsh directories - ansible.builtin.file: - path: "{{ item }}" - state: directory - force: true - loop: - - ~/.zsh - - ~/.zsh/cache +- name: (zsh) Configure zsh + when: (_dotfiles_which_zsh | length) > 0 + block: + - name: (zsh) Make zsh my shell + ansible.builtin.user: + name: "{{ ansible_user }}" + shell: "{{ _dotfiles_which_zsh.stdout }}" + state: present -- name: (zsh) Link function library directories - ansible.builtin.file: - path: ~/.zsh/{{ item }} - src: "{{ role_path }}/files/zsh/{{ item }}" - state: link - force: true - loop: - - init-env-functions - - init-rc-functions - - functions + - name: (zsh) Link startup files + ansible.builtin.file: + path: ~/.{{ item }} + src: "{{ role_path }}/files/zsh/{{ item }}" + state: link + force: true + loop: + - zshenv + - zshrc + - zprofile + + - name: (zsh) Create zsh directories + ansible.builtin.file: + path: "{{ item }}" + state: directory + force: true + loop: + - ~/.zsh + - ~/.zsh/cache + + - name: (zsh) Link function library directories + ansible.builtin.file: + path: ~/.zsh/{{ item }} + src: "{{ role_path }}/files/zsh/{{ item }}" + state: link + force: true + loop: + - init-env-functions + - init-rc-functions + - functions diff --git a/Ansible/roles/dotfiles/vars/main.yml b/Ansible/roles/dotfiles/vars/main.yml new file mode 100644 index 0000000..de5b952 --- /dev/null +++ b/Ansible/roles/dotfiles/vars/main.yml @@ -0,0 +1,11 @@ +_dotfiles_core_packages: + - zsh + - git + - tmux + - neovim + +_dotfiles_package_names: + homebrew: + +_dotfiles_requires_become: + homebrew: false