Unable to get “exclude” option working with unarchive module

﹥>﹥吖頭↗ 提交于 2020-05-29 07:13:48

问题


I have a tar/gzip file I am extracting to a list of hosts using the ansible unarchive module.

The following is a partial list of the contents of configs.tgz:

-rw-rw-r-- ian/ian        1295 2015-09-25 15:27 Makefile
-rw-rw-r-- ian/ian          16 2016-06-21 09:24 .configs
drwxrwxr-x ian/ian           0 2016-02-24 10:18 .bash/
-rw-rw-r-- ian/ian         336 2015-09-25 15:27 .bash/apt.b
-rw-rw-r-- ian/ian         367 2015-09-25 15:27 .bash/gcloud.b
drwxrwxr-x ian/ian           0 2016-06-21 09:22 .vim/
drwxrwxr-x ian/ian           0 2016-06-21 09:22 .vim/plugin/
-rw-rw-r-- ian/ian        3327 2016-06-21 09:17 .vim/plugin/scratch.vim
drwxrwxr-x ian/ian           0 2015-09-25 15:27 .vim/ftplugin/
-rw-rw-r-- ian/ian         521 2015-09-25 15:27 .vim/ftplugin/dokuwiki.vim
-rw-rw-r-- ian/ian        2456 2015-09-25 15:27 .vim/ftplugin/nagios.vim
drwxrwxr-x ian/ian           0 2015-09-25 15:27 .vim/ftdetect/
-rw-rw-r-- ian/ian         149 2015-09-25 15:27 .vim/ftdetect/nagios.vim
-rw-rw-r-- ian/ian         111 2015-09-25 15:27 .vim/ftdetect/zsh-profile.vim
-rw-rw-r-- ian/ian         554 2015-09-25 15:27 .zshrc
drwxrwxr-x ian/ian           0 2015-09-25 15:27 .mutt/
lrwxrwxrwx ian/ian           0 2015-09-25 15:27 .mutt/profile.active -> profile.gmail
-rw-rw-r-- ian/ian         863 2015-09-25 15:27 .mutt/everyone.lst
-rw-rw-r-- ian/ian         310 2015-09-25 15:27 .mutt/vimrc4mail
-rw-rw-r-- ian/ian       11559 2015-09-25 15:27 .mutt/muttrc
-rw-rw-r-- ian/ian         441 2015-09-25 15:27 .screenrc
-rw-rw-r-- ian/ian         131 2015-09-25 15:27 .tmux.conf
-rwxrwxr-x ian/ian        1439 2015-09-25 15:27 xmake

I'd like to extract everything except the .mutt directory, but I can't seem to get the exclude option to work correctly.

Here is what I am getting:

% ansible --version
ansible 2.1.0.0
  config file = /home/ian/Playbooks/ansible.cfg
  configured module search path = Default w/o overrides

% rm -rf /tmp/a; mkdir /tmp/a && ansible localhost -m unarchive -a "src=configs/configs.tgz dest=/tmp/a/ exclude='.mutt'" -vvv
Using /home/ian/Playbooks/ansible.cfg as config file
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: ian
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.54-272347310038797 `" && echo ansible-tmp-1466558533.54-272347310038797="` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.54-272347310038797 `" ) && sleep 0'                                                                                                  
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.64-181689590644032 `" && echo ansible-tmp-1466558533.64-181689590644032="` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.64-181689590644032 `" ) && sleep 0'                                                                                                  
<localhost> PUT /tmp/tmp9TwX54 TO /home/ian/.ansible/tmp/ansible-tmp-1466558533.64-181689590644032/stat
<localhost> EXEC /bin/sh -c 'LANG=C LC_ALL=C LC_MESSAGES=C /usr/bin/python /home/ian/.ansible/tmp/ansible-tmp-1466558533.64-181689590644032/stat; rm -rf "/home/ian/.ansible/tmp/ansible-tmp-1466558533.64-181689590644032/" > /dev/null 2>&1 && sleep 0'                                                                                                            
<localhost> PUT configs/configs.tgz TO /home/ian/.ansible/tmp/ansible-tmp-1466558533.54-272347310038797/source
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.94-189956548033565 `" && echo ansible-tmp-1466558533.94-189956548033565="` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.94-189956548033565 `" ) && sleep 0'                                                                                                  
<localhost> PUT /tmp/tmp2xgO6E TO /home/ian/.ansible/tmp/ansible-tmp-1466558533.94-189956548033565/unarchive
<localhost> EXEC /bin/sh -c 'LANG=C LC_ALL=C LC_MESSAGES=C /usr/bin/python /home/ian/.ansible/tmp/ansible-tmp-1466558533.94-189956548033565/unarchive; rm -rf "/home/ian/.ansible/tmp/ansible-tmp-1466558533.94-189956548033565/" > /dev/null 2>&1 && sleep 0'                                                                                                       
<localhost> EXEC /bin/sh -c 'rm -f -r /home/ian/.ansible/tmp/ansible-tmp-1466558533.54-272347310038797/ > /dev/null 2>&1 && sleep 0'                                                                                                          
localhost | FAILED! => {
    "changed": false,                                                                                                  
    "failed": true,                                                                                                    
    "invocation": {                                                                                                    
        "module_args": {
            "backup": null, 
            "content": null, 
            "copy": true, 
            "creates": null, 
            "delimiter": null, 
            "dest": "/tmp/a/", 
            "directory_mode": null, 
            "exclude": [
                ".mutt"
            ], 
            "extra_opts": [], 
            "follow": false, 
            "force": null, 
            "group": null, 
            "keep_newer": false, 
            "list_files": false, 
            "mode": null, 
            "original_basename": "configs.tgz", 
            "owner": null, 
            "regexp": null, 
            "remote_src": null, 
            "selevel": null, 
            "serole": null, 
            "setype": null, 
            "seuser": null, 
            "src": "/home/ian/.ansible/tmp/ansible-tmp-1466558533.54-272347310038797/source"
        }
    }, 
    "msg": "path /tmp/a/.mutt/profile.active does not exist", 
    "path": "/tmp/a/.mutt/profile.active", 
    "state": "absent"
}

I've tried various iterations of the "exclude" option, including

exclude='[ ".mutt" ]'
exclude='[ ".mutt", ".mutt/*" ]'

These appear to work, but I always end up with the entire contents of the .mutt directory being extracted.

Where am I going wrong?


回答1:


Per the comments, there is a bug logged for this issue.

The work-around is to use a YAML list for the exclusions and to make sure the list exactly matches the path/file stored in the archive.

vars:
  exclusions:
    - ./.mutt

and

unarchive: src=configs/configs.tgz dest=/tmp/a exclude={{ exclusions }}


来源:https://stackoverflow.com/questions/37957188/unable-to-get-exclude-option-working-with-unarchive-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!