How do I write Ansible task for ‘systemctl set-default graphical.target’ without shell/command modules

When you execute systemctl set-default graphical.target you can see this log

Removed symlink /etc/systemd/system/default.target. 
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.

Then you can use file module to create symlink as below

- name: Change default target
  hosts: all
  become: yes
  gather_facts: no

  tasks:
  - name: Change default target to graphical.target
    file:
      src: /usr/lib/systemd/system/graphical.target
      dest: /etc/systemd/system/default.target
      state: link

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top