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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With