ansible plabook 小结
$ cat disk.yml --- - name: Mount the volume hosts: all become: yes become_method: sudo vars: mntname1: /data01 mntname2: /data02 diskname1: /dev/xvdg diskname2: /dev/xvdf tasks: - name: filesystem | Format filesystem: fstype=ext4 dev={{ item }} with_items: - "{{ diskname1 }}" - "{{ diskname2 }}" - name: Creates directory file: path={{ item }} state=directory with_items: - "{{ mntname1 }}" - "{{ mntname2 }}" - name: filesytem | mount dir shell: mount {{ diskname1 }} {{ mntname1 }} && echo "mount {{ diskname1 }} {{ mntname1 }}" >> /etc/rc.local sudo: yes - name: filesytem | mount dir shell: mount {{ diskname2 }} {{ mntname2 }} && echo "mount {{ diskname2 }} {{ mntname2 }}" >> /etc/rc.local sudo: yes
如上:为给磁盘挂载。配合ansible tower 的template选项使用。
ansible 版本为:ansible 2.3.1.0
截图如下:
备注:红色方框内 为赋值内容,配合plabook引用,可以正常使用。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lvm配置:
$ cat lvm.yml --- - name: Create and mount the lvm hosts: all become: yes become_method: sudo vars: mntname: /lvm-01 pvname1: /dev/xvdg pvname2: /dev/xvdf vgname: vg01 lv: lv01 tasks: - name: Install LVM in Ubuntu14 when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version == "14" apt: name=lvm2 state=present - name: Install LVM in Amazon when: ansible_distribution == 'Amazon' yum: name=lvm2 state=latest - name: filesystem | Create pv,vg,lv and file systems lvg: vg={{ vgname }} pvs={{ pvname1 }},{{ pvname2 }} - name: filesystem | create lv lvol: vg={{ vgname }} lv={{ lv }} size=100%FREE - name: filesystem | create fs filesystem: fstype=ext4 dev=/dev/{{ vgname }}/{{ lv }} - name: Creates directory file: path={{ item }} state=directory with_items: - "{{ mntname }}" - name: filesytem | mount dir shell: mount /dev/{{ vgname }}/{{lv}} {{ mntname }} && echo "mount /dev/{{ vgname }}/{{lv}} {{ mntname }}" >> /etc/rc.local
备注:lvm制作的plabook 配合tower的提前赋值
截图如下:
~~~~~~~~~~~~~~~~~~~~~~
配置 user 添加功能的plabook,如下:
$ cat user.yml --- - name: Create and mount the lvm hosts: all become: yes become_method: sudo vars: user: test password: test group: root shell: /bin/bash tasks: - name: Amazon Configuration file modification when: ansible_distribution == 'Amazon' lineinfile: dest: /etc/cloud/cloud.cfg.d/00_defaults.cfg regexp: "{{ item.regexp }}" line: "{{ item.line }}" with_items: - { regexp: '^ssh_pwauth: false', line: 'ssh_pwauth: true' } - { regexp: ' lock_passwd: true', line: ' lock_passwd: false' } - name: create {{ user }} on aws machine user: name={{ user }} password={{ password |password_hash('sha512') }} group={{ group }} shell={{ shell }} - name: config /etc/sudoers lineinfile: dest=/etc/sudoers state=present line='{{item}}' validate='visudo -cf %s' with_items: - "{{ user}} ALL=(ALL) NOPASSWD: ALL" - name: change ssh login lineinfile: dest: /etc/ssh/sshd_config regexp: "{{ item.regexp }}" line: "{{ item.line }}" with_items: - { regexp: 'PasswordAuthentication no', line: 'PasswordAuthentication yes' } - name: restart sshd on Amazon linux when: ansible_distribution == 'Amazon' service: name=sshd state=restarted - name: restart sshd on Ubuntu14 when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version == "14" service: name=ssh state=restarted
备注:vars 里边的信息可以放到tower 的yml里边做提前的声明,方式如同上面两张图片。
# ansible --version
ansible 2.3.1.0
本文来自博客园, 作者:Star-Hitian, 转载请注明原文链接:https://www.cnblogs.com/Star-Haitian/articles/8006463.html