ansible playbook備忘

整理自網絡 方便查看nginx

對變量使用正則

- 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
相關文章
相關標籤/搜索