Ansible Neofetch install script

I love eye candy and I love automation. Combined this means using Ansible to configure Neofetch on Digitalocean droplets which I maintain.

What I particularly like is are the even aligned bars for memory, processor and disks. By default these are practically unreadable.

The below script installs the neofetch package, adjusts the configuration file to my liking and adds an neofetch bash script to the system wide profile.d folder.

All results in the following neofetch welcome when ssh’ing to my droplets.

Code

The install script is as follows:

    - name: Install package
      apt:
        name: neofetch
      register: package_installed

    - name: Add or replace Neofetch configuration /etc/neofetch/config.conf
      lineinfile:
        path: /etc/neofetch/config.conf
        regexp: "{{ item.regexp }}"
        line: "{{ item.line }}"
        #state=absent
      with_items:
        - { regexp: '^.*info "Host" model',                     line: '#    info "Host" model' }
        - { regexp: '^.*info "Packages" packages',              line: '#    info "Packages" packages' }
        - { regexp: '^.*info "Shell" shell',                    line: '#    info "Shell" shell' }
        - { regexp: '^.*info "Terminal" term',                  line: '#    info "Terminal" term' }
        - { regexp: '^.*info "GPU" gpu',                        line: '#    info "GPU" gpu' }
        - { regexp: '^.*info "(OS|Distro)" distro',             line: '    info "Distro" distro' }
        - { regexp: '^.*info "(Disk|\s)" disk',                 line: '    info " " disk' }
        - { regexp: '^.*info "(Memory|Mem)" memory',            line: '    info "Mem" memory' }
        - { regexp: '^.*info "(CPU Usage|CPU)" cpu_usage',      line: '    info "CPU" cpu_usage' }
        - { regexp: '^.*info "Public IP" public_ip',            line: '    info "Public IP" public_ip' }
        - { regexp: '^cpu_display="(barinfo|off)"',             line: 'cpu_display="barinfo"' }
        - { regexp: '^memory_display="(barinfo|off)"',          line: 'memory_display="barinfo"' }
        - { regexp: '^disk_display="(barinfo|off)"',            line: 'disk_display="barinfo"' }
        - { regexp: '^bold="(off|on)"',                         line: 'bold="off"' }
        - { regexp: '^cpu_brand="(off|on)"',                    line: 'cpu_brand="off"' }
        - { regexp: '^speed_shorthand="(on|off)"',              line: 'speed_shorthand="on"' }
        - { regexp: '^distro_shorthand="(on|off)"',             line: 'distro_shorthand="on"' }
      when: package_installed is not failed

    - name: Add or replace (INSERTAFTER) Neofetch configuration /etc/neofetch/config.conf
      lineinfile:
        path: /etc/neofetch/config.conf
        insertafter: "{{ item.insertafter }}"
        line: "{{ item.line }}"
        #state=absent
      with_items:
        - { insertafter: '^.*info "GPU" gpu',           line: '    info line_break' }
        - { insertafter: '^.*info "Local IP" local_ip', line: '    info line_break' }
        - { insertafter: '^.*info underline',           line: '    info line_break' }
      when: package_installed is not failed

    - name: Add or replace Neofetch shell start script
      blockinfile:
        path: /etc/profile.d/neofetch.sh
        marker: "# {mark} Run Neofetch on shell start #"
        create: yes
        block: |
          #!/bin/sh
          echo ""
          neofetch --config none
        backup: no
        insertafter: EOF
      when: package_installed is not failed

Leave a Reply

Your email address will not be published. Required fields are marked *