如果一个特定的apt包丢失,我希望做一系列的任务。
例如:
如果未安装石墨-碳,请执行以下操作:
- apt: name=debconf-utils state=present
- shell: echo 'graphite-carbon/postrm_remove_databases boolean false' | debconf-set-selections
- apt: name=debconf-utils state=absent另一个例子:
如果未安装statsd,请执行以下操作:
- file: path=/tmp/build state=directory
- shell: cd /tmp/build ; git clone https://github.com/etsy/statsd.git ; cd statsd ; dpkg-buildpackage
- shell: dpkg -i /tmp/build/statsd*.deb我该如何开始破解它呢?
我在想,也许我可以做一个-shell: dpkg -l|grep <package name>,以某种方式捕获返回代码。
发布于 2015-02-27 09:31:33
看起来我的解决方案起作用了。
这是一个我是如何工作的例子:
- shell: dpkg-query -W 'statsd'
ignore_errors: True
register: is_statd
- name: create build dir
file: path=/tmp/build state=directory
when: is_statd|failed
- name: install dev packages for statd build
apt: name={{ item }}
with_items:
- git
- devscripts
- debhelper
when: is_statd|failed
- shell: cd /tmp/build ; git clone https://github.com/etsy/statsd.git ; cd statsd ; dpkg-buildpackage
when: is_statd|failed
....下面是另一个示例:
- name: test if create_superuser.sh exists
stat: path=/tmp/create_superuser.sh
ignore_errors: True
register: f
- name: create graphite superuser
command: /tmp/create_superuser.sh
when: f.stat.exists == True...and再来一次
- stat: path=/tmp/build
ignore_errors: True
register: build_dir
- name: destroy build dir
shell: rm -fvR /tmp/build
when: build_dir.stat.isdir is defined and build_dir.stat.isdir发布于 2018-09-28 04:17:13
您可以使用package_facts模块(需要Ansible 2.5):
- name: Gather package facts
package_facts:
manager: apt
- name: Install debconf-utils if graphite-carbon is absent
apt:
name: debconf-utils
state: present
when: '"graphite-carbon" not in ansible_facts.packages'
...发布于 2015-02-27 07:36:41
我认为使用dpkg | grep是正确的,只是在任何情况下返回代码都将是0。但是您可以简单地检查输出。
- shell: dpkg-query -l '<package name>'
register: dpkg_result
- do_something:
when: dpkg_result.stdout != ""https://stackoverflow.com/questions/28754155
复制相似问题