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

Adding --log-opt: max_file to specify the max number of log files. #697

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/podman_container_module.html
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,14 @@ <h2><a class="toc-backref" href="#id3" role="doc-backlink">Parameters</a><a clas
<td><div class="ansible-option-indent-desc"></div><div class="ansible-option-cell"><p>Specify a max size of the log file (e.g 10mb).</p>
</div></td>
</tr>
<tr class="row-odd"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
<div class="ansibleOptionAnchor" id="parameter-log_opt/max_file"></div>
<div class="ansibleOptionAnchor" id="parameter-log_options/max_file"></div><p class="ansible-option-title" id="ansible-collections-containers-podman-podman-container-module-parameter-log-options-max-file"><span id="ansible-collections-containers-podman-podman-container-module-parameter-log-opt-max-file"></span><strong>max_file</strong></p>
<a class="ansibleOptionLink" href="#parameter-log_opt/max_file" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
</div></td>
<td><div class="ansible-option-indent-desc"></div><div class="ansible-option-cell"><p>Specify a max number of the log files (e.g 10).</p>
</div></td>
</tr>
<tr class="row-even"><td><div class="ansible-option-indent"></div><div class="ansible-option-cell">
<div class="ansibleOptionAnchor" id="parameter-log_opt/path"></div>
<div class="ansibleOptionAnchor" id="parameter-log_options/path"></div><p class="ansible-option-title" id="ansible-collections-containers-podman-podman-container-module-parameter-log-options-path"><span id="ansible-collections-containers-podman-podman-container-module-parameter-log-opt-path"></span><strong>path</strong></p>
Expand Down
7 changes: 5 additions & 2 deletions plugins/module_utils/podman/podman_container_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
log_opt=dict(type='dict', aliases=['log_options'],
options=dict(
max_size=dict(type='str'),
max_file=dict(type='str'),
path=dict(type='str'),
tag=dict(type='str'))),
mac_address=dict(type='str'),
Expand Down Expand Up @@ -466,13 +467,15 @@ def addparam_log_driver(self, c):
def addparam_log_opt(self, c):
for k, v in self.params['log_opt'].items():
if v is not None:
if k in ('max_file', 'max_size'):
opt = k.replace('_', '-')
c += ['--log-opt',
b"=".join([to_bytes(k.replace('max_size', 'max-size'),
errors='surrogate_or_strict'),
b"=".join([to_bytes(opt, errors='surrogate_or_strict'),
to_bytes(v,
errors='surrogate_or_strict')])]
return c


def addparam_log_level(self, c):
return c + ['--log-level', self.params['log_level']]

Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/podman_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@
- Specify a max size of the log file (e.g 10mb).
type: str
required: false
max_file:
description:
- Specify a max number of the log files (e.g 10).
type: str
required: false
tag:
description:
- Specify a custom log tag for the container.
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/podman_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
- Specify a max size of the log file (e.g 10mb).
type: str
required: false
max_file:
description:
- Specify a max number of the log files (e.g 10).
type: str
required: false
tag:
description:
- specify a custom log tag for the container. This option is currently supported only by the journald log driver in Podman.
Expand Down Expand Up @@ -337,6 +342,7 @@ def main():
log_opt=dict(type='dict', aliases=['log_options'], options=dict(
path=dict(type='str'),
max_size=dict(type='str'),
max_file=dict(type='str'),
tag=dict(type='str'))),
network=dict(type='list', elements='str'),
state=dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
log_opt:
path: /tmp/container3.log
max_size: 100mb
max_file: '10'
tag: sometag
command: 1h

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
log_opt:
path: "{{ log_opt.path }}"
max_size: "{{ log_opt.size }}"
max_file: "{{ log_opt.file }}"
AhmadKasem marked this conversation as resolved.
Show resolved Hide resolved
register: play_pod

- name: Get pod info
Expand All @@ -43,6 +44,7 @@
- play_container_info.containers.0.Config.Annotations["greet_to"] == "world"
- play_container_info.containers.0.HostConfig.LogConfig["Path"] == log_opt.path
- play_container_info.containers.0.HostConfig.LogConfig["Size"] | lower == log_opt.size
- play_container_info.containers.0.HostConfig.LogConfig["Size"] | lower == log_opt.file

always:

Expand Down