Change Wallpaper on Gnome Desktop’s using Ansible

Setup Wallpaper on Ubuntu using Ansible

Today, In this article we will setup the Gnome Desktop setting using Ansible Playbook.

1) Setting up inventory file for remote hosts.

For the inventory, I created a file hosts and filled it with following content details.

/etc/ansible# cat hosts
server1 ansible_host= ansible_user=gaurav ansible_ssh_pass=123 ansible_connection=ssh
server2 ansible_host= ansible_user=gaurav ansible_ssh_pass=123 ansible_connection=ssh 
server3 ansible_host= ansible_user=gaurav ansible_ssh_pass=123 ansible_connection=ssh

2) Script to change the wallpaper on remote machine.

This script changes the wallpaper from a given directory on remote systems.

#! /bin/bash
wget "$SRC_URI" -O "$FNAME"
PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
sleep 5
/usr/bin/gsettings set org.gnome.desktop.background picture-uri $DNAME

3) Setting up playbook.

In third step I created the playbook (i.e playbook.yaml) and add hosts (ansible run this playbook for all available hosts).
I set ‘become’ to true to activate privilege escalation and use ‘become_method’ as a sudo (In our case ‘gaurav’ is the sudo user).

  name: 'Change Wallpaper on Gnome Desktop's using Ansible'
  hosts: remoteservers
  become: True
  become_method: sudo
    - name: 'create a directory for Wallpaper'
        path: /home/gaurav/Pictures/.wallpaper/
        state: directory
        owner: gaurav
        group: gaurav
        mode: '0775' 
    - name: 'Copy wallpaper to remote systems'
        src: /etc/ansible/playbook/
        dest: /home/gaurav/Pictures/.wallpaper/
        owner: gaurav
        group: gaurav
        mode: '0777'
    - name: 'Change wallpaper on remote system'
        name: 'wallpaper change'
        minute: "*"
        hour: "*/3"
        day: "*"
        month: "*"
        weekday: "*"
        job: /home/gaurav/Pictures/.wallpaper/
        user: gaurav
        state: present
        - cronjobs  
      become: False

In this playbook, First copy the script i.e “” to “/home/gaurav/Pictures/.wallpaper/” directory on remote servers and set the cron that will execute every 3 hours on remote system.

3) Execute the playbook.

Execute the playbook in ansible server using below command.

root@ansible:/etc/ansible/playbook# ansible-playbook playbook.yaml --ask-become-pass

Hope this post will help Devops beginners. Please share you feedback and Comments. Stay tune for more updates with …!!!

Leave a Reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notify of