How to create and edit a file with ansible

969 Views Asked by At

I need to execute the next Role with ansible and somehow it doesn't work. The idea is to create a sddm.conf file and add some lines in. When I run the role all goes like normal, even says that it did changes, but when I look in the destiny computer, the file is not there.

---
# tasks file for 5ssdm
- name: sddm.conf erstellen
  shell: |
    cat <<EOF
    >/etc/sddm.conf
    [Autologin]
    # Whether sddm should automatically log back into sessions when they exit
    Relogin=false

    # Name of session file for autologin session (if empty try last logged in)
    Session=

    # Username for autologin session
    User=


    [General]
    # Halt command
    HaltCommand=/bin/systemctl poweroff

    # Input method module
    InputMethod=compose

    # Initial NumLock state. Can be on, off or none.
    # If property is set to none, numlock won't be changed
    # NOTE: Currently ignored if autologin is enabled.
    Numlock=none

    # Reboot command
    RebootCommand=/bin/systemctl reboot


    [Theme]
    # Current theme name
    Current=maldives

    # Cursor theme used in the greeter
    CursorTheme=

    # Number of users to use as threshold
    # above which avatars are disabled
    # unless explicitly enabled with EnableAvatars
    DisableAvatarsThreshold=7

    # Enable display of custom user avatars
    EnableAvatars=true

    # Global directory for user avatars
    # The files should be named <username>.face.icon
    FacesDir=/usr/share/sddm/faces

    # Theme directory path
    ThemeDir=/usr/share/sddm/themes


    [Users]
    # Default $PATH for logged in users
    DefaultPath=/bin:/usr/bin


    EOF

1

There are 1 best solutions below

1
On BEST ANSWER

Prefer using the template or the copy modules to accomplish that, like this:

---
- name: Create SDDM configuration
  copy:
    dest: /etc/sddm.conf
    group: root
    mode: 0644
    owner: root
    src: sddm.conf

Best regards.