Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ansible

I want to write a task in Ansible to perform the following command:

"systemctl set-default graphical.target" without using shell/command modules.

not sure that the "ansible.builtin.systemd" module has this option.

like image 238
Ilana Polonsky Avatar asked Nov 05 '20 16:11

Ilana Polonsky


People also ask

How do you get a default target?

To see your current default, run systemctl get-default. To change back to the command-line interface, execute systemctl set-default multi-user. target, as depicted in the image below.

What is default systemd target?

The default. target file is a symbolic link to the true target file. For a desktop workstation, this is typically going to be the graphical. target, which is equivalent to runlevel 5 in SystemV.


1 Answers

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
like image 198
gary lopez Avatar answered Oct 05 '22 12:10

gary lopez