ansible playbook备忘

整理自网络 方便查看

对变量使用正则

- name: Extract tomcat archive
  command: chdir=/opt/software /bin/tar xvf /tmp/{{tomcat_bin_file}} -C /opt/software creates={{tomcat_bin_file|regex_replace('(.*).tar.gz$', '\\1') }

取目录中文件为变量

- name: check conf.d
  shell: (cd /etc/nginx/conf.d/; find . -maxdepth 1 -type f) | cut -d'/' -f2
  register: files_to_fetch
  tags: fetch_nginx_conf

- name: fetch conf.d
  fetch: src=/etc/nginx/conf.d/{{ item }}
         dest=conf_files/nginx_conf/{{ansible_hostname}}_{{ansible_default_ipv4.address}}/conf.d/
         flat=yes
  with_items:  files_to_fetch.stdout_lines

指定组执行

- name: my command
  command: echo stuff
  when: "'groupname' not in group_names"

指定不执行

 ansible-playbook --limit 'all:!oadb01' sync_repos.yml

ip address

{{ ansible_default_ipv4.address }}
{{ ansible_eth0.ipv4.address }}

判断目录是否挂载

- name: check if /opt/xxx is mounted or not
  command: mountpoint -q /opt/xxx
  register: volume_stat
  failed_when: False
  changed_when: False

- name: debug
  debug: msg="/opt/xxx is mounted"
  when: volume_stat.rc == 0

转载于:https://my.oschina.net/firxiao/blog/820629

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值