如何使用ansible创建和编辑文件

How to create and edit a file with ansible

我需要用 ansible 执行下一个角色,但不知何故它不起作用。这个想法是创建一个 sddm.conf 文件并在其中添加一些行。 当我运行这个角色一切正常,甚至说它有变化,但是当我在命运电脑中查看时,文件不存在

---
# 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

更喜欢使用 templatecopy 模块来完成此操作,如下所示:

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

此致。