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

echo: command doesn't support condition #240

Closed
umputun opened this issue Dec 18, 2024 Discussed in #238 · 5 comments · Fixed by #241
Closed

echo: command doesn't support condition #240

umputun opened this issue Dec 18, 2024 Discussed in #238 · 5 comments · Fixed by #241

Comments

@umputun
Copy link
Owner

umputun commented Dec 18, 2024

Discussed in #238

Originally posted by dstull December 18, 2024
the echo command, nor using an echo in a script: outputs to the console. Am I doing something wrong?

See below:

echo as a command:

  • yml setup:
user: ubuntu
ssh_key: /home/ubuntu/.ssh/id_rsa
ssh_shell: /bin/bash
local_shell: /bin/bash
inventory: inventory.yml

tasks:
  - name: Check known rails issue 366450
    targets: ["gitlab_rails"]
    commands:
      - name: Display warning message
        echo: "If you're using SAML for OmniAuth you might be running into known issue https://gitlab.com/gitlab-org/gitlab/-/issues/366450"
  • output:
ubuntu@sr-env-049aca04-omnibus:~$ ./spot -p rails_known_issues.yml --env GITLAB_VERSION:16.0.0
spot v1.16.1-3c62f53-2024-10-23T16:26:56Z
[omnibus localhost:22] run task "Check known rails issue 366450", commands: 1
[omnibus localhost:22] completed command "Display warning message" {echo: If you're using SAML for OmniAuth you might be running into known issue https://gitlab.com/gitlab-org/gitlab/-/issues/366450} (927ms)
[omnibus localhost:22] completed task "Check known rails issue 366450", commands: 1 (982ms)

echo in a script:

  • yml setup:
user: ubuntu
ssh_key: /home/ubuntu/.ssh/id_rsa

targets: ["localhost:22"]
task:
  - name: Check known rails issue 366450
    echo: "If you're using SAML for OmniAuth you might be running into known issue https://gitlab.com/gitlab-org/gitlab/-/issues/366450"
  • output:
ubuntu@sr-env-049aca04-omnibus:~$ ./spot -p rails_known_issues.yml --env GITLAB_VERSION:16.0.0
spot v1.16.1-3c62f53-2024-10-23T16:26:56Z
[localhost:22] run task "default", commands: 1
[localhost:22] completed command "Check known rails issue 366450" {echo: If you're using SAML for OmniAuth you might be running into known issue https://gitlab.com/gitlab-org/gitlab/-/issues/366450} (458ms)
[localhost:22] completed task "default", commands: 1 (511ms)

I expected the echo output would show the actual echo instead this appears as just a statement of the command being issued, not a actual echo to the console.

umputun added a commit that referenced this issue Dec 18, 2024
umputun added a commit that referenced this issue Dec 18, 2024
* add condition support to echo, see #240

* format tests

* clarify condition limitation
@umputun
Copy link
Owner Author

umputun commented Dec 18, 2024

@dstull the change on master. Please give it a try and see if it resolves the issue. I have covered the change with decent tests but have not tried it manually. I think it will work the way you expect it to work.

in case if you have troubles building it - let me know if you need binary (pls specify for what platform in this case) and i will attach

@umputun umputun reopened this Dec 18, 2024
@dstull
Copy link

dstull commented Dec 18, 2024

@umputun awesome! It will probably be quicker if you had a minute to build it than for me right now as I'd have to figure a few things out. So if you have the time linux amd64 is the type/build I've been using

@umputun
Copy link
Owner Author

umputun commented Dec 19, 2024

sure: spot.master.zip

@dstull
Copy link

dstull commented Dec 19, 2024

@umputun tested locally with config of

user: ubuntu
ssh_key: /home/ubuntu/.ssh/id_rsa
ssh_shell: /bin/bash
local_shell: /bin/bash
inventory: inventory.yml

tasks:
  - name: Check known rails issue 366450
    targets: ["gitlab_rails"]
    commands:
      - name: Condition check
        script: |
          rm -f /tmp/366450
          version=${GITLAB_VERSION//./}
          if [[ $version -gt 1500 && $version -lt 1630 ]]; then
            touch /tmp/366450
          fi
      - name: Checking for known issue
        script: |
          if grep -s 'OmniAuth::Strategies::SAML' /etc/gitlab/gitlab.rb | grep strategy_class; then
            touch /tmp/366450_warning
          fi
        on_exit: "rm -fv /tmp/366450"
        options: {ignore_errors: true, sudo: true}
        cond: "test -f /tmp/366450"
      - name: Display warning message
        echo: "If you're using SAML for OmniAuth you might be running into known issue https://gitlab.com/gitlab-org/gitlab/-/issues/366450"
        cond: "test -f /tmp/366450_warning"
      - name: Cleanup temp files
        script: |
          rm -fv /tmp/366450_warning
        options: {ignore_errors: true, sudo: true}
  - name: Fake issue that will fail
    targets: ["gitlab_rails"]
    commands:
      - name: Condition check
        script: |
          rm -f /tmp/fake
          version=${GITLAB_VERSION//./}
          if [[ $version -gt 1500 && $version -lt 1700 ]]; then
            touch /tmp/fake
          fi
      - name: Checking condition for known fake issue
        script: |
          if grep -s "gitlab_backup_cli\['dir'\]" /etc/gitlab/gitlab.rb | grep '/var/opt/gitlab/backups'; then
            touch /tmp/fake_warning
          fi
        on_exit: "rm -fv /tmp/fake"
        options: {ignore_errors: true, sudo: true}
        cond: "test -f /tmp/fake"
      - name: Display warning message
        echo: "If this is set to backups, that is wrong. Make sure you fix that."
        cond: "test -f /tmp/fake_warning"
      - name: Cleanup temp files
        script: |
          rm -fv /tmp/fake_warning
        options: {sudo: true}
  • output:
ubuntu@sr-env-049aca04-omnibus:~$ ./spot -p rails_known_issues.yml --env GITLAB_VERSION:1600
spot dev-master
[omnibus localhost:22] run task "Check known rails issue 366450", commands: 4
[omnibus localhost:22] completed command "Condition check" {script: /bin/sh -c [multiline script]} (806ms)
[omnibus localhost:22] completed command "Checking for known issue" {script: /bin/sh -c [multiline script]} (108ms)
[omnibus localhost:22] completed command "Display warning message" {skip: Display warning message} (8ms)
[omnibus localhost:22] completed command "Cleanup temp files" {script: /bin/sh -c [multiline script]} (45ms)
[omnibus localhost:22] completed task "Check known rails issue 366450", commands: 4 (1.021s)
[omnibus localhost:22] run task "Fake issue that will fail", commands: 4
[omnibus localhost:22] completed command "Condition check" {script: /bin/sh -c [multiline script]} (229ms)
[omnibus localhost:22] completed command "Checking condition for known fake issue" {script: /bin/sh -c [multiline script]} (55ms)
[omnibus localhost:22] completed command "Display warning message" {echo: If this is set to backups, that is wrong. Make sure you fix that.} (9ms)
[omnibus localhost:22] completed command "Cleanup temp files" {script: /bin/sh -c [multiline script]} (35ms)
[omnibus localhost:22] completed task "Fake issue that will fail", commands: 4 (402ms)

verified!

  • the 1st one skips as expected and doesn't show echo
  • the 2nd one runs as expected and shows echo

@umputun
Copy link
Owner Author

umputun commented Dec 19, 2024

cool. will release an updated version shortly

@umputun umputun closed this as completed Dec 19, 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

Successfully merging a pull request may close this issue.

2 participants