Giter Site home page Giter Site logo

.dotfiles's Introduction

dotfiles

  1. Setup credentials.yml
  2. Execution
  3. File Descriptions

Setup credentials.yml:

Generate SSH Keys:

ssh-keygen -t rsa -b 4096

generate_ssh_keys

Verify SSH Key Creation:

  • List the files in your current directory to ensure the keys were created:
ls

list_the_keys

Copy Public Key to GitHub:

  1. Display your public key with the following command:
cat your_text_file
  1. Copy the entire output of this command.
  2. Open your web browser and go to GitHub SSH and GPG keys settings.
  3. Click New SSH key.
  4. Paste your key into the "Key" field.
  5. Add a descriptive title, such as "My Laptop Key".
  6. Click Add SSH key.

Encrypt the SSH Key Using Ansible Vault:

  • Store a single key in a file your_text_file & encrypt like this for all the keys. For ssh keys, use those files as it is.

  • Similarly, you can store any kind of text in a file & encrypt it

ansible-vault encrypt your_text_file

encrypt_the_public_key_using_ansible_vault

encrypt_the_private_key_using_ansible_vault

Verify Key Encryption:

  • Check the contents of the encrypted file:
cat your_text_file

encrypted_public_key

Indent the Encrypted Key (two spaces):

  1. Open the encrypted file in a text editor (e.g., VS Code).

  2. Select all text with Ctrl + a.

  3. Indent the text by pressing Tab.

  4. Save the file with Ctrl + s.

encrypted_and_indented_public_key

Save the value in credentials.yml:

  1. Open credentials.yml in a text editor.

  2. Copy the encrypted and indented key from your file.

  3. Paste it into the appropriate place in credentials.yml while checking personal_git.yml or work_git.yml, to ensure that the variable name is correct.

store_it_in_credentials.yml



Execution:

macOS:

Install Ansible & Homebrew:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/suyashbhawsar/dotfiles/main/macOS-setup.sh)"

Note: Quit & re-open the Terminal

Set up git:

Note: You'll be prompted to enter the password to decrypt the encrypted values you've created using Ansible vault.

ansible-pull -U https://github.com/suyashbhawsar/dotfiles --vault-id @prompt --tags mac-minimal,mac-full git.yml

Install 'Minimal' Packages & Configurations:

ansible-pull -U https://github.com/suyashbhawsar/dotfiles --tags mac-minimal install.yml

Install 'Full' Packages & Configurations:

ansible-pull -U https://github.com/suyashbhawsar/dotfiles --tags mac-full install.yml

Remove Packages & Configurations:

ansible-pull -U https://github.com/suyashbhawsar/dotfiles --tags mac remove.yml

Linux

Clone the repo & build the docker image

cd ~/ && rm -rf dotfiles && git clone https://github.com/suyashbhawsar/dotfiles.git && (if docker ps -a --format '{{.Names}}' | grep -q "^debian-ansible$"; then \
    docker stop debian-ansible; \
fi && \
if docker ps -a --format '{{.Names}}' | grep -q "^debian-ansible$"; then \
    docker rm debian-ansible; \
fi && \
if docker images --format '{{.Repository}}:{{.Tag}}' | grep -q "^debian-ansible:"; then \
    docker rmi debian-ansible; \
fi && \
docker build -t debian-ansible ~/dotfiles)

Start a container from the docker image

docker run -it --rm debian-ansible /bin/bash

Set up git:

Note: You'll be prompted to enter the password to decrypt the encrypted values you've created using Ansible vault.

ansible-pull -U https://github.com/suyashbhawsar/dotfiles --vault-id @prompt --tags linux git.yml

Install Packages & Configurations:

ansible-pull -U https://github.com/suyashbhawsar/dotfiles --tags linux install.yml

Remove Packages & Configurations:

ansible-pull -U https://github.com/suyashbhawsar/dotfiles --tags linux remove.yml

File Descriptions:

Dockerfile:

Defines the Docker image with all necessary dependencies for running Ansible on a Debian-based system.


macOS-setup.sh:

This macOS-setup.sh script is designed to automate the installation of essential development tools on macOS. It checks for the presence of Homebrew, Python3, Ansible, and Stow, and installs them if they are not already installed. The script ensures that your development environment is set up correctly and efficiently.

  • Script Overview:
    • File Name: macOS-setup.sh
    • Purpose: Automates the installation of Homebrew, Python3, Ansible, and Stow on macOS.
  • Script Breakdown:
    1. Checking and Installing Homebrew

      if ! command -v brew >/dev/null 2>&1; then
        echo -e "\033[1;34mInstalling Homebrew\033[0m"
        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
        echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
        eval "$(/opt/homebrew/bin/brew shellenv)"
      else
        echo -e "\033[1;34mHomebrew is already installed\033[0m"
      fi
      • Purpose: Checks if Homebrew is installed and installs it if not.
      • Details:
        • Check: command -v brew checks if the brew command is available.
        • Installation: If Homebrew is not found, it is installed using the official installation script from Homebrew's GitHub repository.
        • Environment Setup: Adds Homebrew to the shell environment by appending eval "$(/opt/homebrew/bin/brew shellenv)" to ~/.zprofile and then evaluates the command.
    2. Checking and Installing Python3

      if ! command -v python3 >/dev/null 2>&1; then
        echo -e "\033[1;34mInstalling Python\033[0m"
        brew install python
      else
        echo -e "\033[1;34mPython is already installed\033[0m"
      fi
      • Purpose: Checks if Python3 is installed and installs it if not.
      • Details:
        • Check: command -v python3 checks if the python3 command is available.
        • Installation: If Python3 is not found, it is installed using Homebrew with the command brew install python.
    3. Checking and Installing Ansible

      if ! command -v ansible >/dev/null 2>&1; then
        echo -e "\033[1;34mInstalling Ansible\033[0m"
        brew install ansible
      else
        echo -e "\033[1;34mAnsible is already installed\033[0m"
      fi
      • Purpose: Checks if Ansible is installed and installs it if not.
      • Details:
        • Check: command -v ansible checks if the ansible command is available.
        • Installation: If Ansible is not found, it is installed using Homebrew with the command brew install ansible.
    4. Checking and Installing Stow

      if ! command -v stow >/dev/null 2>&1; then
        echo -e "\033[1;34mInstalling Stow\033[0m"
        brew install stow
      else
        echo -e "\033[1;34mStow is already installed\033[0m"
      fi
      • Purpose: Checks if Stow is installed and installs it if not.
      • Details:
        • Check: command -v stow checks if the stow command is available.
        • Installation: If Stow is not found, it is installed using Homebrew with the command brew install stow.

credentials.yml:

The credentials.yml file is an Ansible variable file used to securely store sensitive information such as Git credentials and SSH keys. This file utilizes Ansible Vault to encrypt sensitive data, ensuring that it remains secure. Below is a detailed explanation of the contents and structure of the credentials.yml file.

  • Script Overview:
    • File Name: credentials.yml
    • Purpose: Stores sensitive personal and work-related credentials securely using Ansible Vault.
  • Variables Breakdown:
    1. personal_git_username

      personal_git_username: "suyashbhawsar"
      • Purpose: Placeholder for personal Git username.
      • Details:
        • Variable Name: personal_git_username
        • Value: "suyashbhawsar" (Your GitHub Personal Account username)
    2. personal_git_email

      personal_git_email: !vault |
        $ANSIBLE_VAULT;1.1;AES256
        33346234333739633337643138353332646438646539616138623136376665633937623934346566
        3933366634383537336536363632653661303363373364380a653537366431643161633236613764
        35373037313433373638613961383632656634316530633231636633636663313330333364633634
        3434626335323037300a313530333937653866663461663137663530363330336538326466353262
        37386434363661303766366365633235316363613738333031396630323031343933
      • Purpose: Placeholder for encrypted personal Git email address.
      • Details:
        • Variable Name: personal_git_email
        • Value: Encrypted string (Email Address) using Ansible Vault
    3. personal_ssh_key_public

      personal_ssh_key_public: !vault |
        $ANSIBLE_VAULT;1.1;AES256
        63643130346438346133376336613730356562616464373633636361656633663265616538313466
        3763336434343962623138343331326333333061663433350a306261623037343063396135636635
        ....
      • Purpose: Placeholder for encrypted public SSH key.
      • Details:
        • Variable Name: personal_ssh_key_public
        • Value: Encrypted string (Public SSH Key) using Ansible Vault
    4. personal_ssh_key_private

      personal_ssh_key_private: !vault |
        $ANSIBLE_VAULT;1.1;AES256
        36343535663139613931343264303465623830653539386133653236626363323839643963346365
        6339353936343531636262326437396263643261636435330a663734353937363533306335666164
        ....
      • Purpose: Placeholder for encrypted private SSH key.
      • Details:
        • Variable Name: personal_ssh_key_private
        • Value: Encrypted string (Private SSH Key) using Ansible Vault

personal_git.yml & work_git.yml:

These Ansible playbooks are designed to configure Git settings, manage SSH keys, and clone .dotfiles Git repository. Below is a detailed explanation of each section and task in the playbook:

  • Playbook Overview:
    • Variable Files:
      • credentials.yml (This file contains sensitive information such as your personal Git username, email, and SSH keys.)
    • Tasks Breakdown:
      1. Git Configuration

        Task 1: Set Git user.name

        - name: "Git | Set user.name"
          community.general.git_config:
            name: user.name
            scope: global
            value: "{{ personal_git_username }}"
          become: false
        • Purpose: Configures the global Git username.
        • Details:
          • Module: community.general.git_config
          • Parameter name: Sets the Git configuration variable user.name.
          • Parameter scope: global indicates the setting is applied globally.
          • Parameter value: Uses the variable personal_git_username (personal_git.yml) or work_git_username (work_git.yml) from credentials.yml.
          • Parameter become: false ensures that the task does not require elevated privileges.

        Task 2: Set Git user.email

        - name: "Git | Set user.email"
          community.general.git_config:
            name: user.email
            scope: global
            value: "{{ personal_git_email }}"
          become: false
        • Purpose: Configures the global Git email.
        • Details:
          • Module: community.general.git_config
          • Parameter name: Sets the Git configuration variable user.email.
          • Parameter scope: global indicates the setting is applied globally.
          • Parameter value: Uses the variable personal_git_email (personal_git.yml) or work_git_email (work_git.yml) from credentials.yml.
          • Parameter become: false ensures that the task does not require elevated privileges.
      2. SSH Key Management

        Task 3: Create .ssh Directory

        - name: Create .ssh directory
          file:
            path: "{{ ansible_user_dir }}/.ssh"
            state: directory
            mode: '0700'
          become: false
        • Purpose: Ensures the existence of the .ssh directory with the correct permissions.
        • Details:
          • Module: file
          • Parameter path: Creates the directory at the path {{ ansible_user_dir }}/.ssh.
          • Parameter state: directory ensures the path is a directory.
          • Parameter mode: Sets permissions to 0700 (read, write, execute for owner only).
          • Parameter become: false ensures that the task does not require elevated privileges.

        Task 4: Copy Public SSH Key

        - name: "SSH | Copy personal_rsa Public SSH key"
          copy:
            dest: "{{ ansible_user_dir }}/.ssh/personal_rsa.pub"
            content: "{{ personal_ssh_key_public }}"
            mode: '0644'
          become: false
        • Purpose: Copies the public SSH key to the .ssh directory.
        • Details:
          • Module: copy
          • Parameter dest: Destination path for the public key.
          • Parameter content: Uses the variable personal_ssh_key_public (personal_git.yml) or work_ssh_key_public (work_git.yml) from credentials.yml.
          • Parameter mode: Sets permissions to 0644 (read and write for owner, read for others).
          • Parameter become: false ensures that the task does not require elevated privileges.

        Task 5: Copy Private SSH Key

        - name: "SSH | Copy personal_rsa Private SSH key"
          copy:
            dest: "{{ ansible_user_dir }}/.ssh/personal_rsa"
            content: "{{ personal_ssh_key_private }}"
            mode: '0600'
          become: false
        • Purpose: Copies the private SSH key to the .ssh directory.
        • Details:
          • Module: copy
          • Parameter dest: Destination path for the private key.
          • Parameter content: Uses the variable personal_ssh_key_private (personal_git.yml) or work_ssh_key_private (work_git.yml) from credentials.yml.
          • Parameter mode: Sets permissions to 0600 (read and write for owner only).
          • Parameter become: false ensures that the task does not require elevated privileges.
      3. Repository Management (Only in personal_git.yml)

        Task 6: Remove Existing Repository Directory

        - name: Remove repository directory
          file:
            path: ~/.dotfiles
            state: absent
          become: false
        • Purpose: Ensures the removal of any existing .dotfiles directory to avoid conflicts.
        • Details:
          • Module: file
          • Parameter path: Path to the .dotfiles directory.
          • Parameter state: absent ensures the directory is removed if it exists.
          • Parameter become: false ensures that the task does not require elevated privileges.

        Task 7: Clone Repository

        - name: Clone repository
          shell: GIT_SSH_COMMAND="ssh -i ~/.ssh/temp" git clone [email protected]:{{ personal_git_username }}/.dotfiles.git ~/.dotfiles
          become: false
        • Purpose: Clones the specified Git repository into the .dotfiles directory.
        • Details:
          • Module: shell
          • Command: Uses a custom SSH command to clone the repository from GitHub.
          • Parameter GIT_SSH_COMMAND: Specifies the SSH command with the appropriate private key.
          • Repository URL: [email protected]:{{ personal_git_username }}/.dotfiles.git
          • Destination: Clones into the ~/.dotfiles directory.
          • Parameter become: false ensures that the task does not require elevated privileges.

install.yml:

Ansible playbook that runs the post-stow configuration (from the private repository: .dotfiles) after installing and configuring packages.

install.yml:

The install.yml file is a part of the Ansible setup and is responsible for running post-configuration tasks after the initial git configuration. This file imports another playbook located in the user's home directory under .dotfiles.

  • File Overview:
    • File Name: install.yml
    • Purpose: Runs post-configuration tasks after git configuration by importing another playbook.
  • Variables Breakdown:
    1. Running Post-Git Configuration

      - name: Run post-git configuration
        import_playbook: "{{ lookup('env', 'HOME') }}/.dotfiles/post_git.yml"
      • Purpose: Imports and runs the post_git.yml playbook located in the user's .dotfiles directory.
      • Details:
        • Task Name: Run post-git configuration
        • Module: import_playbook
        • Parameter import_playbook: Specifies the path to the post_git.yml playbook.
          • Path: The path is dynamically set using lookup('env', 'HOME') to get the user's home directory and appending .dotfiles/post_git.yml.

remove.yml:

Playbook to remove installed packages and configurations (both git.yml & post_git.yml) by importing remove_all.yml from the .dotfiles repository.

.dotfiles's People

Contributors

suyashbhawsar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.