Ansible using RCS for File Backup

Some time ago, a user suggested to Ansible that the incorporate RCS for configuration backup. The idea was rejected as this was not a feature Ansible wished to implement. I can understand such a decision, as RCS is somewhat tricky to deal with, particularly if you check files out in an unlocked state. The read-only permissions would create a headache for Ansible. This would necessitate checking any files out in a locked state while Ansible runs other updates.

However, it is actually rather trivial to implement such an integration, provided you are willing to allow files to remain “locked” from an RCs viewpoint.

The Ansible code is simply a handler, and I have provided an example below, with a few details changed.

- name: Deploy website
  hosts: my.host.com
  remote_user: root
  handlers:
    - name: check in update log
      shell: ci -l -f -t-"Website update log" -m"Automatic backup" /root/website-update.log
  tasks:
    - name: Deploy website bundle
      unarchive: 
        src: "{{ playbook_dir }}/www.miersma.ca.tar.gz"
        dest: /var/www/html/
        owner: root
        group: root
    - name: Update deploy log
      shell: echo "Deployed www.miersma.ca on $(date)" > /root/website-update.log
      notify: 
        - check in update log

It is possible to use RCS to track any files. Arguably, it would even be possible to handle RCS locking in a more traditional manner, however, that would necessarily increase the complexity of the Ansible code by requireing pre_tasks and possibly post_tasks. In addition, the file permissions would not line up with any permissions set by Ansible. However, with ci -l and a few flags for automatic description and messages, it is trivial to achieve such an integration.