-
I would like to figure out how I could best templatize a set task with commands. My goal is to maintain a common list of commands for a set list of input. The benefit would be that the template of commands would not need changed and then contributors to my use of spot can merely provide changes to the list of issues. I see https://spot.umputun.dev/#export mentioned to do some gen using go templating, but I can't see that it supports something like this...yet. Do you have any advice on how to handle this case using spot? for example, given this list of issues(tasks): tasks:
- issue_number: 366450
check_command: grep -s 'OmniAuth::Strategies::SAML' /etc/gitlab/gitlab.rb
warning_message: "If you're using SAML for OmniAuth you might be running into known issue https://gitlab.com/gitlab-org/gitlab/-/issues/366450"
version:
started: 1500
fixed: 1630
- issue_number: 365810
check_command: grep -Es '^(\s*[^#]\s*)?gitlab_rails.*?object_store.*?=.*?\/.*' /etc/gitlab/gitlab.rb
warning_message: "If your object storage configuration uses slashes in bucket names you might be running into known issue https://gitlab.com/gitlab-org/gitlab/-/issues/365810"
version:
started: 1500
fixed: 1520 and then this template: user: ubuntu
ssh_key: /home/ubuntu/.ssh/id_rsa
ssh_shell: /bin/bash
local_shell: /bin/bash
inventory: inventory.yml
tasks:
- name: "Checking condition for known issue {{ item.issue_number }}"
targets: ["gitlab_rails"]
commands:
- name: Run the check and store result
script: |
json_data_{{ item.issue_number }}=$(cat <<EOF
{
"issue_link": "https://gitlab.com/gitlab-org/gitlab/-/issues/{{ item.issue_number }}",
"warning_message": "{{ item.warning_message }}",
"version_started": "{{ item.version.started }}",
"version_fixed": "{{ item.version.fixed }}",
}
EOF
)
register: [json_data_{{ item.issue_number }}]
options: { ignore_errors: true }
cond: |
version=${GITLAB_VERSION//./}
[[ $version -gt {{ item.version.started }} && $version -lt {{ item.version.fixed }} && `{{ item.check_command}}` ]]
- name: Collect into report file locally
script: |
echo "$json_data_{{ item.issue_number }}" > /tmp/issue_{{ item.issue_number }}.json
options: { ignore_errors: true, local: true } I would then get a generated playbook like this: user: ubuntu
ssh_key: /home/ubuntu/.ssh/id_rsa
ssh_shell: /bin/bash
local_shell: /bin/bash
inventory: inventory.yml
tasks:
- name: "Checking condition for known issue 366450"
targets: ["gitlab_rails"]
commands:
- name: Run the check and store result
script: |
json_data_366450=$(cat <<EOF
{
"issue_link": "https://gitlab.com/gitlab-org/gitlab/-/issues/366450",
"warning_message": "If you're using SAML for OmniAuth you might be running into known issue https://gitlab.com/gitlab-org/gitlab/-/issues/366450",
"version_started": "1500",
"version_fixed": "1630",
}
EOF
)
register: [json_data_366450]
options: { ignore_errors: true }
cond: |
version=${GITLAB_VERSION//./}
[[ $version -gt 1500 && $version -lt 1630 && `grep -s 'OmniAuth::Strategies::SAML' /etc/gitlab/gitlab.rb` ]]
- name: Collect into report file locally
script: |
echo "$json_data_366450" > /tmp/issue_366450.json
options: { ignore_errors: true, local: true }
- name: "Checking condition for known issue 365810"
targets: ["gitlab_rails"]
commands:
- name: Run the check and store result
script: |
json_data_365810=$(cat <<EOF
{
"issue_link": "https://gitlab.com/gitlab-org/gitlab/-/issues/365810",
"warning_message": "If your object storage configuration uses slashes in bucket names you might be running into known issue https://gitlab.com/gitlab-org/gitlab/-/issues/365810",
"version_started": "1500",
"version_fixed": "1520",
}
EOF
)
register: [json_data_365810]
options: { ignore_errors: true }
cond: |
version=${GITLAB_VERSION//./}
[[ $version -gt 1500 && $version -lt 1520 && `grep -Es '^(\s*[^#]\s*)?gitlab_rails.*?object_store.*?=.*?\/.*' /etc/gitlab/gitlab.rb` ]]
- name: Collect into report file locally
script: |
echo "$json_data_365810" > /tmp/issue_365810.json
options: { ignore_errors: true, local: true } |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The export support you mentioned has very little to do with any of this. See #105 for what it does. The generation of playbooks from templates and with some template inputs is not supported. However, if someone can propose a PR providing this functionality without inflating the code base significantly, I'll consider it. In the meantime, you can probably try to emulate this behavior in the spot by using environment variables in the playbook and passing them in from some external utility, parsing your list of tasks. |
Beta Was this translation helpful? Give feedback.
The export support you mentioned has very little to do with any of this. See #105 for what it does.
The generation of playbooks from templates and with some template inputs is not supported. However, if someone can propose a PR providing this functionality without inflating the code base significantly, I'll consider it.
In the meantime, you can probably try to emulate this behavior in the spot by using environment variables in the playbook and passing them in from some external utility, parsing your list of tasks.