2

I'm trying to avoid a list of 'command' modules in my ansible play, but there seems to be a void of ansible docs regarding tar/gz and the synch module seems... incomplete.

I'd like to gzip a tarball of a big directory then rsync it to another host. Even using 'command' seems to not work for me :<

 "warnings": ["Consider using unarchive module rather than running tar"]}
 [WARNING]: Consider using unarchive module rather than running tar


PLAY RECAP *********************************************************************
ctarlctarl                 : ok=2    changed=0    unreachable=0    failed=1   

The 'unarchive' module seems to expect an already compressed/archived directory and doesn't appear to be the solution I want.

Related but unanswered: ansible playbook unable to continue as the `tar` fails due to `file change as we read`

(Edit) showing the task since it was asked if I remembered the z. =)

  - name: tar ball app dir, exclude conf files
    command: "tar -zcvf {{ item.code_dir }}.tar.gz --exclude '*config*' ."
    args:
      chdir:  "{{ apps_home }}/{{ item.code_dir }}"
    with_items:
      - "{{ processes }}"
Community
  • 1
  • 1
ddro
  • 201
  • 1
  • 3
  • 10
  • These command warnings of ansible are rather dump. They just check the first word in a command and if it matches a list it will complain. It does not take into account that you can do much more with the `tar` command than unarchiving... You can avoid the warning by: `- command: \`which tar\` ...` – udondan Feb 16 '16 at 05:05
  • But that warning only is a warning. The fail comes form something else. – udondan Feb 16 '16 at 05:06
  • you remembered the -z right? – kpie Feb 16 '16 at 05:14

3 Answers3

1

In version 2.2 ansible will get an archive module: https://docs.ansible.com/ansible/archive_module.html

With that you can archive, transfer and unarchive all with ansible modules and don't have to fiddle with command line arguments.

Robin Roth
  • 1,289
  • 10
  • 13
0

So, I got it working... just inelegantly.

  1. With the v flag set, my ansible stdout was horrendously verbose (even without calling -vvvv with ansible-playbook). Turning off the switch inside the tar command made tracking down the problem easier.
  2. The problem was actually the error "error: file changed as we read it" - no doubt because I was adding the archive file into the directory it was compressing. I solved it by simply moving the archived file up a directory when running.

This, however, leaves me with the 'command after command' solution - which is what I hope I'll eventually be able to avoid. Half way there, though.

ddro
  • 201
  • 1
  • 3
  • 10
-1

This warning tip you can use the ansible unarchive module instead of tar commnad. The syntax is very easy just like below:

- unarchive: src=foo.tgz dest=/var/lib/foo

And more detail info you can got from here: unarchive_module

elkan1788
  • 97
  • 1
  • 2
  • 11