ansible-podman-collections icon indicating copy to clipboard operation
ansible-podman-collections copied to clipboard

podman play module with multi-documents yaml files fails

Open micheelengronne opened this issue 1 year ago • 2 comments

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

When using the podman_play module with a kubefile containing multiple documents and using recreate=True, the modules fails because it does not accept multi-documents.

Steps to reproduce the issue:

  1. Run a play with an ansible kube play step and a kube file with multiple documents

  2. Run it again

  3. The error appears

Describe the results you received:

runpy.run_module(mod_name='ansible_collections.containers.podman.plugins.modules.podman_play', init_globals=dict(_module_fqn='ansible_collections.containers.podman.plugins.modules.podman_play', _modlib_path=modlib_path), File "/usr/lib/python3.10/runpy.py", line 224, in run_module return _run_module_code(code, init_globals, run_name, mod_spec) File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code _run_code(code, mod_globals, init_globals, File "/usr/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/tmp/ansible_containers.podman.podman_play_payload_mhhijc07/ansible_containers.podman.podman_play_payload.zip/ansible_collections/containers/podman/plugins/modules/podman_play.py", line 311, in <module> File "/tmp/ansible_containers.podman.podman_play_payload_mhhijc07/ansible_containers.podman.podman_play_payload.zip/ansible_collections/containers/podman/plugins/modules/podman_play.py", line 300, in main File "/tmp/ansible_containers.podman.podman_play_payload_mhhijc07/ansible_containers.podman.podman_play_payload.zip/ansible_collections/containers/podman/plugins/modules/podman_play.py", line 251, in play File "/tmp/ansible_containers.podman.podman_play_payload_mhhijc07/ansible_containers.podman.podman_play_payload.zip/ansible_collections/containers/podman/plugins/modules/podman_play.py", line 239, in pod_recreate File "/tmp/ansible_containers.podman.podman_play_payload_mhhijc07/ansible_containers.podman.podman_play_payload.zip/ansible_collections/containers/podman/plugins/modules/podman_play.py", line 194, in discover_pods File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 162, in safe_load return load(stream, SafeLoader) File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 114, in load return loader.get_single_data() File "/usr/lib/python3/dist-packages/yaml/constructor.py", line 49, in get_single_data node = self.get_single_node() File "/usr/lib/python3/dist-packages/yaml/composer.py", line 41, in get_single_node raise ComposerError("expected a single document in the stream", yaml.composer.ComposerError: expected a single document in the stream

Describe the results you expected:

The containers to be redeployed.

Additional information you deem important (e.g. issue happens only occasionally):

Version of the containers.podman collection: Either git commit if installed from git: git show --summary Or version from ansible-galaxy if installed from galaxy: ansible-galaxy collection list | grep containers.podman

1.10.3

Output of ansible --version:

8.5.0

Output of podman version:

4.6.2

Output of podman info --debug:

(paste your output here)

Package info (e.g. output of rpm -q podman or apt list podman):

(paste your output here)

Playbok you run with ansible (e.g. content of playbook.yaml):

(paste your output here)

Command line and output of ansible run with high verbosity

Please NOTE: if you submit a bug about idempotency, run the playbook with --diff option, like:

ansible-playbook -i inventory --diff -vv playbook.yml

(paste your output here)

Additional environment details (AWS, VirtualBox, physical, etc.):

micheelengronne avatar Oct 28 '23 14:10 micheelengronne

Can you please paste an example of multi-document yaml file?

sshnaidm avatar Nov 01 '23 14:11 sshnaidm

Of course, every document that contains multiple --- yaml separator. For instance: https://kubernetes.io/docs/concepts/cluster-administration/manage-deployment/#organizing-resource-configurations

micheelengronne avatar Nov 04 '23 13:11 micheelengronne

It's reproducible with a yaml file having multi documents like below, which is cited from podman-kube-play(1).

apiVersion: v1
kind: ConfigMap
metadata:
  name: foo
data:
    FOO: bar
---
apiVersion: v1
kind: Pod
metadata:
  name: foobar
spec:
  containers:
  - name: container-1
    image: foobar
    envFrom:
    - configMapRef:
        name: foo
        optional: false

I guess we need to use yaml.safe_load_all() instead of yaml.safe_load(): https://github.com/containers/ansible-podman-collections/blob/fea8b255e59192c4a31acd177debbf6506632e5d/plugins/modules/podman_play.py#L189-L194

nishipy avatar Mar 09 '24 15:03 nishipy