Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Admin, DevOps, Security
  3. Automation
  4. I know this is a long shot but: Is there a way to loop over a set of tasks in ansible and changing "remote_user" (not "become_user")?

I know this is a long shot but: Is there a way to loop over a set of tasks in ansible and changing "remote_user" (not "become_user")?

Scheduled Pinned Locked Moved Automation
ansibleprovisioningsysadmin
12 Posts 3 Posters 1 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • davdr@fosstodon.orgD davdr@fosstodon.org

    @dwardoric check out https://github.com/linux-system-roles/systemd/blob/main/tasks/manage_units.yml where they so the same (probably) as what you need: use `become` with`become_user` and set `XDG_RUNTIME_DIR`

    dwardoric@chaos.socialD This user is from outside of this forum
    dwardoric@chaos.socialD This user is from outside of this forum
    dwardoric@chaos.social
    wrote last edited by
    #3

    @davdr Thanks, I'll take a look.

    dwardoric@chaos.socialD 1 Reply Last reply
    0
    • dwardoric@chaos.socialD dwardoric@chaos.social

      @davdr Thanks, I'll take a look.

      dwardoric@chaos.socialD This user is from outside of this forum
      dwardoric@chaos.socialD This user is from outside of this forum
      dwardoric@chaos.social
      wrote last edited by
      #4

      @davdr Sadly using that approach ends up with exactly the same error. So I guess I will take a stab at machinectl.

      davdr@fosstodon.orgD 1 Reply Last reply
      0
      • dwardoric@chaos.socialD dwardoric@chaos.social

        @davdr Sadly using that approach ends up with exactly the same error. So I guess I will take a stab at machinectl.

        davdr@fosstodon.orgD This user is from outside of this forum
        davdr@fosstodon.orgD This user is from outside of this forum
        davdr@fosstodon.org
        wrote last edited by
        #5

        @dwardoric could it be because systemd lingering was not enabled for that user?

        Anyway, one way I used machinectl before (from the systemd-container package) is:

        $ sudo machinectl shell myuser@

        This should drop you in a shell for *myuser*, where you can execute systemctl commands like you would normally expect. For example:

        $ systemctl --user list-units

        dwardoric@chaos.socialD 1 Reply Last reply
        0
        • davdr@fosstodon.orgD davdr@fosstodon.org

          @dwardoric could it be because systemd lingering was not enabled for that user?

          Anyway, one way I used machinectl before (from the systemd-container package) is:

          $ sudo machinectl shell myuser@

          This should drop you in a shell for *myuser*, where you can execute systemctl commands like you would normally expect. For example:

          $ systemctl --user list-units

          dwardoric@chaos.socialD This user is from outside of this forum
          dwardoric@chaos.socialD This user is from outside of this forum
          dwardoric@chaos.social
          wrote last edited by
          #6

          @davdr There is a step running "loginctl enable-linger"

          Everything is fine when I simply connect as the user (setting "remote_user"). However that only allows one "service setup" per host. Also I try to not hack my way around ansible but so far I fear that this use case is just not existent in its scope.

          I hope "become_method: machinectl" will help.

          badnetmask@hachyderm.ioB 1 Reply Last reply
          0
          • dwardoric@chaos.socialD dwardoric@chaos.social

            @davdr There is a step running "loginctl enable-linger"

            Everything is fine when I simply connect as the user (setting "remote_user"). However that only allows one "service setup" per host. Also I try to not hack my way around ansible but so far I fear that this use case is just not existent in its scope.

            I hope "become_method: machinectl" will help.

            badnetmask@hachyderm.ioB This user is from outside of this forum
            badnetmask@hachyderm.ioB This user is from outside of this forum
            badnetmask@hachyderm.io
            wrote last edited by
            #7

            @dwardoric @davdr
            I have some internal playbooks where I connect as the regular user, with "become: true" at the top, then "become:false" at each of the tasks that need to run systemd as user. It doesn't work for blocks, only for individual tasks. What I don't know is if it's possible to become a user different than the one you are ssh'ing as.

            dwardoric@chaos.socialD 1 Reply Last reply
            0
            • badnetmask@hachyderm.ioB badnetmask@hachyderm.io

              @dwardoric @davdr
              I have some internal playbooks where I connect as the regular user, with "become: true" at the top, then "become:false" at each of the tasks that need to run systemd as user. It doesn't work for blocks, only for individual tasks. What I don't know is if it's possible to become a user different than the one you are ssh'ing as.

              dwardoric@chaos.socialD This user is from outside of this forum
              dwardoric@chaos.socialD This user is from outside of this forum
              dwardoric@chaos.social
              wrote last edited by
              #8

              @davdr @badnetmask Thanks but I need to run the play multiple times for different users. I can simply split out the user creation into another play but still cannot run the user specific stuff in a loop because this doesn't seem possible AFAIK. Looping over tasks doesn't use remote_user and looping over play_include is not supported. 😞

              davdr@fosstodon.orgD 1 Reply Last reply
              0
              • dwardoric@chaos.socialD dwardoric@chaos.social

                @davdr @badnetmask Thanks but I need to run the play multiple times for different users. I can simply split out the user creation into another play but still cannot run the user specific stuff in a loop because this doesn't seem possible AFAIK. Looping over tasks doesn't use remote_user and looping over play_include is not supported. 😞

                davdr@fosstodon.orgD This user is from outside of this forum
                davdr@fosstodon.orgD This user is from outside of this forum
                davdr@fosstodon.org
                wrote last edited by
                #9

                @dwardoric @badnetmask and yet this is what https://github.com/linux-system-roles/systemd does, no? Maybe your error is related to another issue?

                dwardoric@chaos.socialD 1 Reply Last reply
                0
                • davdr@fosstodon.orgD davdr@fosstodon.org

                  @dwardoric @badnetmask and yet this is what https://github.com/linux-system-roles/systemd does, no? Maybe your error is related to another issue?

                  dwardoric@chaos.socialD This user is from outside of this forum
                  dwardoric@chaos.socialD This user is from outside of this forum
                  dwardoric@chaos.social
                  wrote last edited by
                  #10

                  @badnetmask @davdr They use become which is not sufficient as we discussed. The root cause seems to be systemd not being able to talk to dbus because dbus will not be started when using become. I'm still investigating machinectl. The sledgehammer method would of course be doing all the symlink magic systemd does via script but I'd like to not have a "hacky, against the system" solution. 😉

                  davdr@fosstodon.orgD 1 Reply Last reply
                  0
                  • dwardoric@chaos.socialD dwardoric@chaos.social

                    @badnetmask @davdr They use become which is not sufficient as we discussed. The root cause seems to be systemd not being able to talk to dbus because dbus will not be started when using become. I'm still investigating machinectl. The sledgehammer method would of course be doing all the symlink magic systemd does via script but I'd like to not have a "hacky, against the system" solution. 😉

                    davdr@fosstodon.orgD This user is from outside of this forum
                    davdr@fosstodon.orgD This user is from outside of this forum
                    davdr@fosstodon.org
                    wrote last edited by
                    #11

                    @dwardoric @badnetmask dbus errors are typically due to lingering not being active, or XDG_RUNTIME_DIR not being set. But you had lingering active already, you said. Welcome to the wonderful world of systemd 🙂 It can work, but I’m afraid I can’t advise any more than what I already shared.
                    If all else fails, maybe you should try the latest Claude/Gemini/ChatPT LLM’s to let them come up with a minimal code example that is equivalent to what you’re trying to do.

                    dwardoric@chaos.socialD 1 Reply Last reply
                    0
                    • davdr@fosstodon.orgD davdr@fosstodon.org

                      @dwardoric @badnetmask dbus errors are typically due to lingering not being active, or XDG_RUNTIME_DIR not being set. But you had lingering active already, you said. Welcome to the wonderful world of systemd 🙂 It can work, but I’m afraid I can’t advise any more than what I already shared.
                      If all else fails, maybe you should try the latest Claude/Gemini/ChatPT LLM’s to let them come up with a minimal code example that is equivalent to what you’re trying to do.

                      dwardoric@chaos.socialD This user is from outside of this forum
                      dwardoric@chaos.socialD This user is from outside of this forum
                      dwardoric@chaos.social
                      wrote last edited by
                      #12

                      @badnetmask @davdr The really sad thing is that I could solve it with a couple of lines shell-script. 😉
                      Maybe I should just print out a note at the end of the ansible run to do so. 😅

                      1 Reply Last reply
                      0
                      • incentiveI incentive moved this topic from Uncategorized
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups