- hosts: nfs
become: yes
vars:
share_path: /mnt/nfsroot
nfs_ip: ""
nfs_hostname: ""
vars_files:
- /home/ansible/user-list.txt
tasks:
- name: Ensure users are present
user:
name:
state: present
loop:
- dev_user
- qa_user
- prod_user
- name: configure exports
template:
src: /home/ansible/exports.j2
dest: /etc/exports
notify: update nfs
handlers:
- name: update nfs exports
command: exportfs -a
listen: update nfs
ansible-playbook --syntax-check webserver.yml
// copy file
copy:
src: /home/ansible/scripts.tgz
dest: /mnt/storage/
// create user
user:
name: xyzcorp_network
state: present
// install pkg
yum:
name: nmap-ncat
state: latest
// install pkg
package:
name: elinks
state: latest
// update fine
lineinfile:
path: /etc/hosts
line: "ansible.xyzcorp.com 169.168.0.1"
// manage service
service:
name: nfs-server
state: started
enabled: yes
// create file or dir
file:
state: directory
path: /home/noc/.ssh
mode: 0600
owner: noc
group: noc
// use template
template:
src: /home/ansible/exports.j2
dest: /etc/exports
// check file status
stat:
path: /opt/user-agreement.txt
register: filestat
// run cmd
command: /opt/data-job.sh
async: 600
poll: 0
tags:
- data-job
// create user when file exist
user:
name: ""
when: filestat.stat.exists
loop: ""
需要设置.ansible-navigator.yml文件和build相应的execution environment
ansible-navigator run playbook.yml -i inv --limit hostname -e "api_key=xxx ansible_python_interpreter=/usr/bin/python"
ansible-navigator inventory -i inv.yml --list
:) 未完待续……
LEo at 00:12