DEV Community

Discussion on: Build your own system with ArchLinux

Collapse
 
samuelfaure profile image
Samuel-Zacharie FAURE • Edited

Sure ! Here's an example from my actual config. What it does is simply :

  • deletes a list of configuration files on my system (if they exist) with a loop (the list itself is on another file)
  • Creates the config folders I'll need to copy my configuration
  • Symlink the configuration files from my playbook to the system (so we replace the files we deleted before with the proper version, that is the version saved on the playbook)
---
- name: Delete existing Dotfiles
  file:
    path: '~/{{ item }}'
    state: absent
  loop: "{{ Dotfiles }}"

- name: Create .config folder
  file:
    path: '~/.config'
    state: directory

- name: Create .config/Code - OSS folder
  file:
    path: '~/.config/Code - OSS'
    state: directory

- name: Link Dotfiles into home
  file:
    src: "{{ playbook_dir }}/roles/dotfiles/files/{{ item }}"
    dest: '~/.{{ item }}'
    state: link
    force: yes
  loop: "{{ Dotfiles }}"

Note this is all done with the same ansible module, "file". Here's another task somewhere else that uses the module "package", which is used to install my list of packages :

- name: Install packages with pacman
  become_user: root
  package:
    state: present
    name: "{{ item }}"
  loop: "{{ packages }}"
  tags: packages-list