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

Make Ansible Playbook more readable and apply best practices #730

Merged
merged 4 commits into from
Sep 18, 2024

Conversation

maximiliankolb
Copy link
Contributor

Please review commit by commit.

Local reproducer without Foreman/Katello:

---
- name: "Run script"
  hosts: localhost
  vars:
    url: "http://foreman.example.com/pub/test.sh"
  tasks:
    - name: "Download script"
      ansible.builtin.uri:
        url: "{{ url }}"
        return_content: true
      register: script_response
    - name: "Run script"
      ansible.builtin.shell:
        cmd: |
          {{ script_response.content }}
      register: out
      changed_when: true  # noqa: no-changed-when
    - name: "Show output"
      ansible.builtin.debug:
        var: out

Then run ansible-playbook my_playbook.yaml which results in the following output:

PLAY [Run script] ********************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Download script] ***************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Run script] ********************************************************************************************************************************************************************************************
changed: [localhost]

TASK [Show output] *******************************************************************************************************************************************************************************************
ok: [localhost] => {
    "out": {
        "changed": true,
        "cmd": "#!/bin/bash\n\necho \"hello world\"\n",
        "delta": "0:00:00.002726",
        "end": "2024-08-16 14:59:04.530418",
        "failed": false,
        "rc": 0,
        "start": "2024-08-16 14:59:04.527692",
        "stderr": "",
        "stderr_lines": [],
        "stdout": "hello world\n",
        "stdout_lines": [
            "hello world"
        ]
    }
}

@ekohl
Copy link
Member

ekohl commented Sep 3, 2024

It feels like they should be rendered in tests (as snapshots) and then run ansible-lint on them.

@maximiliankolb
Copy link
Contributor Author

Rebased to "master"; hoping for green GHA.

@maximiliankolb
Copy link
Contributor Author

I don't know what error such as the following mean:

I, [2024-09-12T15:28:32.745506 #4116]  INFO -- /default_dead_letter_handler: got dead letter #<Concurrent::Actor::Envelope:295440> @message=:check_delayed_plans, @sender=#<Dynflow::ClockReference:0x000055d586536e78 /clock (Dynflow::Clock)>, @address=#<Concurrent::Actor::Reference:0x000055d586c8e568 /delayed-executor (Dynflow::DelayedExecutors::PollingCore)>>

This happens on test:foreman_ansible - Foreman develop with Ruby 2.7 and Node 14 on PostgreSQL 13.

@nofaralfasi
Copy link
Contributor

I don't know what error such as the following mean:

I, [2024-09-12T15:28:32.745506 #4116]  INFO -- /default_dead_letter_handler: got dead letter #<Concurrent::Actor::Envelope:295440> @message=:check_delayed_plans, @sender=#<Dynflow::ClockReference:0x000055d586536e78 /clock (Dynflow::Clock)>, @address=#<Concurrent::Actor::Reference:0x000055d586c8e568 /delayed-executor (Dynflow::DelayedExecutors::PollingCore)>>

This happens on test:foreman_ansible - Foreman develop with Ruby 2.7 and Node 14 on PostgreSQL 13.

Ignore that. It's a known issue and unrelated to your changes.

Copy link
Contributor

@nofaralfasi nofaralfasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @maximiliankolb!

@nofaralfasi nofaralfasi merged commit 4ec6884 into theforeman:master Sep 18, 2024
22 of 27 checks passed
@maximiliankolb maximiliankolb deleted the rework_ansible_playbook branch September 19, 2024 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants