[英]Compiling and installing a simple binary using Ansible
说我有一个非常简单的程序magic_command.c
,我想将其编译为magic_command
并安装在/usr/local/bin
。
我可以想到的一种方法是使用Ansible:
magic_command.c
和一个Makefile
复制到临时目录 make all
创建magic_command
make install
,该目标将magic_command
复制到/usr/local/bin
使用Ansible是否有更简单或更简洁的方法?
我最终使用的方法与原始问题中所述的方法非常相似:
- name: Create temporary directory for compilation
command: mktemp -d /tmp/magic_command.XXXXXXXXX
register: magic_command_temp_dir
- name: Copy source and makefile
copy: src={{ item }} dest={{ magic_command_temp_dir.stdout }}
with_items:
- magic_command.c
- Makefile
- name: Compile executable
shell: make chdir={{ magic_command_temp_dir.stdout }}
- name: Install executable
copy: remote_src=True src={{ magic_command_temp_dir.stdout }}/magic_command dest=/usr/local/bin/magic_command mode=0755 owner=root group=root
- name: Remove temporary directory
file: name={{ magic_command_temp_dir.stdout }} state=absent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.