Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change behavior of register directive to apply it to all following tasks #196

Closed
umputun opened this issue Apr 27, 2024 · 4 comments
Closed

Comments

@umputun
Copy link
Owner

umputun commented Apr 27, 2024

currently, exporting a var or setting them to register acts the same way - making the var available for other commands in the given task. I think this is the correct logic for set var, but incorrect for register. The proposed change will update all the following tasks by injecting register vars into them.

see #195 (reply in thread) for more details

umputun added a commit that referenced this issue Apr 27, 2024
The runner now differentiates between all variables and registered variables from command execution. Registered variables are a subset of all variables that will be used for subsequent tasks. This additional feature aids in more specific tracking and utilization of key variables in more complex scripting scenarios. This is a preparation step to implement cross-task registered vars #196
@umputun
Copy link
Owner Author

umputun commented Apr 27, 2024

@koolay - the change in place on the :master image. Pls, give it a try and see if it fixes the reported issue

@koolay
Copy link

koolay commented Apr 28, 2024

Hi, it is not work when target host is not on the same host.
@umputun

@umputun
Copy link
Owner Author

umputun commented Apr 28, 2024

The change shouldn't be tied to any target host but rather propagate it to all the tasks. If it doesn't work for you, please provide the playbook and output of the spot with --dbg and -v.

This is the one I have tested and it worked as expected:

user: umputun
ssh_key: ~/.ssh/id_rsa

targets:
  dev1:
    hosts: [{host: "dev1.umputun.dev", name: "dev1"}]
  dev2:
    hosts: [{host: "dev2.umputun.dev", name: "dev2"}]

tasks:
  - name: first
    targets: ["dev1"]
    commands:
      - name: get host name
        script: |
            myhost=$(hostname)
        register: [myhost]

  - name: second
    targets: ["dev2"]
    commands:
      - name: show host name
        script: |
            echo "show myhost var: $myhost"
[dev1 dev1.umputun.dev:22] run task "first", commands: 1
[dev1 dev1.umputun.dev:22] run command "get host name"
[dev1 dev1.umputun.dev:22]  > /bin/sh -c /tmp/.spot-8947750978994702336/spot-script1300844333
[dev1 dev1.umputun.dev:22]  > setvar myhost=dev1.umputun.dev
[dev1 dev1.umputun.dev:22] completed command "get host name" {script: /bin/sh -c [multiline script]} (79ms)
[dev1 dev1.umputun.dev:22] completed task "first", commands: 1 (150ms)
[dev2 dev2.umputun.dev:22] run task "second", commands: 1
[dev2 dev2.umputun.dev:22] run command "show host name"
[dev2 dev2.umputun.dev:22]  > /bin/sh -c 'myhost="dev1.umputun.dev"; echo "show myhost var: $myhost"'
[dev2 dev2.umputun.dev:22]  > show myhost var: dev1.umputun.dev
[dev2 dev2.umputun.dev:22] completed command "show host name" {script: /bin/sh -c 'myhost="dev1.umputun.dev"; echo "show myhost var: $myhost"'} (8ms)
[dev2 dev2.umputun.dev:22] completed task "second", commands: 1 (91ms)

As you can see, myhost was set on dev1 and later echoed on dev2.

@koolay
Copy link

koolay commented Apr 28, 2024

@umputun
I have found the why. I use spot as lib. The main.go has changed, I should update my code also.

image

@umputun umputun closed this as completed May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants