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

Feature: Add include option to unarchive #40522

Merged
merged 11 commits into from
Dec 7, 2020

Conversation

sijis
Copy link
Contributor

@sijis sijis commented May 22, 2018

SUMMARY

This should allow users to extract specific files from an archive as desired.

Fixes #16130, #27081.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

unarchive

ANSIBLE VERSION
ansible 2.6.0a1 (feature/unarchive/add_include_option 70f23af274) last updated 2018/05/22 01:18:14 (GMT -500)
  config file = /home/saviles/data/git/github/ansible/ansible.cfg
  configured module search path = ['/home/saviles/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/saviles/data/git/github/ansible/lib/ansible
  executable location = /home/saviles/data/git/github/ansible/bin/ansible
  python version = 3.6.5 (default, Mar 29 2018, 18:20:46) [GCC 8.0.1 20180317 (Red Hat 8.0.1-0.19)]

ADDITIONAL INFORMATION

Playbook

- hosts: localhost
  vars:
    issue: 16130
    src_dir: "files/{{ issue }}"
    dst_dir: "/tmp/{{ issue }}"
  tasks:
    - name: Create directory
      file:
        state: directory
        path: "{{item}}"
      with_items:
        - "{{src_dir}}"
        - "{{dst_dir}}"
        - "{{dst_dir}}-tar"
    - name: Create files
      shell: "touch {{src_dir}}/{include,exclude}-{0..9}.txt"

    - name: Create archive file
      archive:
        format: "zip"
        path: "{{src_dir}}/*"
        dest: "{{src_dir}}.zip"
    - name: Unpack zip file
      unarchive:
        src: "{{src_dir}}.zip"
        dest: "{{dst_dir}}"
        remote_src: yes
        include:
          - 'include-2.txt'
      register: unzipped

    - name: Create archive file
      archive:
        format: "tar"
        path: "{{src_dir}}/*"
        dest: "{{src_dir}}.tar"
    - name: Unpack zip file
      unarchive:
        src: "{{src_dir}}.tar"
        dest: "{{dst_dir}}-tar"
        # remote_src: yes
        include:
          - 'include-4.txt'

Output

$ tree /tmp/16130*
/tmp/16130
└── include-2.txt
/tmp/16130-tar
└── include-4.txt

0 directories, 2 files

@ansibot
Copy link
Contributor

ansibot commented May 22, 2018

@ansibot ansibot added affects_2.6 This issue/PR affects Ansible v2.6 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. m:unarchive This issue/PR relates to the unarchive module. labels May 22, 2018
@ansibot
Copy link
Contributor

ansibot commented May 22, 2018

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

lib/ansible/modules/files/unarchive.py:0:0: E322 "include" is listed in the argument_spec, but not documented in the module

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels May 22, 2018
@sijis sijis changed the title feature: Add include option to unarchive [WIP] feature: Add include option to unarchive May 22, 2018
@ansibot ansibot added the WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. label May 22, 2018
@sijis sijis force-pushed the feature/unarchive/add_include_option branch from 70f23af to d0594c9 Compare May 22, 2018 14:36
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label May 22, 2018
@ansibot
Copy link
Contributor

ansibot commented May 22, 2018

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

lib/ansible/modules/files/unarchive.py:0:0: E309 version_added for new option (include) should be 2.6. Currently 0.0

click here for bot help

@ansibot ansibot added the ci_verified Changes made in this PR are causing tests to fail. label May 22, 2018
@sijis sijis force-pushed the feature/unarchive/add_include_option branch from d0594c9 to 47f3e0f Compare May 22, 2018 14:55
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label May 22, 2018
@sijis
Copy link
Contributor Author

sijis commented May 22, 2018

The only thing left is adding integration tests.

@sijis sijis force-pushed the feature/unarchive/add_include_option branch from 47f3e0f to 43aaaa9 Compare May 23, 2018 05:14
@ansibot ansibot added the test This PR relates to tests. label May 23, 2018
@sijis
Copy link
Contributor Author

sijis commented May 23, 2018

Added tests for zip archive. Need to complete for gz.

@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label May 24, 2018
@sijis sijis force-pushed the feature/unarchive/add_include_option branch from 43aaaa9 to 1bc5657 Compare May 25, 2018 04:29
@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label May 25, 2018
@sijis sijis force-pushed the feature/unarchive/add_include_option branch from 1bc5657 to 0b9491b Compare May 25, 2018 04:55
@ansibot ansibot removed the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label May 25, 2018
@sijis
Copy link
Contributor Author

sijis commented May 25, 2018

Added fix to tar files including tests.
I also had to rebase, as the excludes feature fix PR was added.

@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 12, 2018
@ansibot ansibot added the files Files category label Mar 5, 2019
@cacack
Copy link

cacack commented May 3, 2019

@sijis Any word on this? Writing a playbook right now that would greatly benefit from being able to whitelist the files to extract...

@tchernomax
Copy link
Contributor

LGTM

though I would have use fnmatch.fnmatch(member, include) (as in exclude), but I can understand that "include" should not use glob.

@@ -802,6 +822,7 @@ def main():
list_files=dict(type='bool', default=False),
keep_newer=dict(type='bool', default=False),
exclude=dict(type='list', default=[]),
include=dict(type='list', default=[]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for taking a while to review this one! Do you mind rebasing this, updating the version added, and adding a changelog?

This option should probably be mutually exclusive with exclude - i.e. AnsibleModule(..., mutually_exclusive=[('exclude', 'include',)])

@ansibot ansibot added pre_azp This PR was last tested before migration to Azure Pipelines. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Dec 4, 2020
sijis and others added 6 commits December 4, 2020 14:46
This should allow users to extract specific files from an archive as
desired.

Fixes ansible#16130, ansible#27081.
- move to separate tasks file
- change assertions to check for exactly one file
- use remote_tmp_dir for output dir
@samdoran samdoran force-pushed the feature/unarchive/add_include_option branch from 64a8571 to 4bba39b Compare December 4, 2020 21:04
@ansibot
Copy link
Contributor

ansibot commented Dec 4, 2020

The test ansible-test sanity --test validate-modules [explain] failed with 2 errors:

lib/ansible/modules/unarchive.py:0:0: parameter-list-no-elements: Argument 'include' in argument_spec defines type as list but elements is not defined
lib/ansible/modules/unarchive.py:0:0: parameter-type-not-in-doc: Argument 'include' in argument_spec defines type as 'list' but documentation doesn't define type

click here for bot help

@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html pre_azp This PR was last tested before migration to Azure Pipelines. labels Dec 4, 2020
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 4, 2020
@sijis
Copy link
Contributor Author

sijis commented Dec 5, 2020

@samdoran Thanks for rebasing and moving this along.

@samdoran samdoran merged commit 034e9b0 into ansible:devel Dec 7, 2020
@samdoran
Copy link
Contributor

samdoran commented Dec 8, 2020

@sijis Sorry it took us so long to merge this. Thank you for your contribution.

@ansible ansible locked and limited conversation to collaborators Jan 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. files Files category m:unarchive This issue/PR relates to the unarchive module. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an "include" parameter to unarchive
7 participants