Ansible + Python = Automated RPM
Published in
8 min readJan 28, 2020
Preface / Disclaimer
The following is the result of project driven by need rather than design, therefore treat this more of a programmatic brain dump than a tutorial! (even though it does work!).
What You Will Need
For this to work you will need the following:
ansible
, an rpmbuild
building environment (Check out my article on how to set this up.) , A unix
machine.
note: I used a local and a remote machine for this, the local was my ansible machine & the remote had my rpm build env.
The Playbook
- name: Create an RPM Package from a download link
hosts: <HOST GOES HERE>
tasks:
- name: download zip to get contents
get_url:
url: "{{ url }}"
dest: /home/builder/- name: grab contents of package
shell: 'unzip -l /home/builder/*.zip > /home/builder/content.txt'- name: strip file of unwanted lines
shell: awk '/{{ package }}\//' /home/builder/content.txt > /home/builder/cut_content.txt- name: strip file of unwanted lines
become: yes
shell: ed "/home/builder/cut_content.txt" <<<$'1d\nwq\n'- name: remove all before package name
shell: "sed 's/.*{{…