Speaker: Apua
Date: 2014.12.25
Location: CLBC
Activity: Taipei.py
Name: Michael DeHaan Projects: - Cobbler: a Linux provisioning server - FUNC: role: co-author name: Fedora Unified Network Controller desc: > a framework for remote administration of Linux
# ansible $inventory -m $module -a $arguments
ansible all -m uri -a 'url=http://8.8.8.8'
# ansible-doc $module
ansible-doc uri
ansible-doc --list
# command (default)
ansible myhosts -m shell -a 'echo $TERM'
# gathering features
ansible myhosts -m setup
# change user and sudo
ansible myhosts -a "/usr/bin/foo" -u username --sudo
# file transfer
ansible myhosts atlanta -m copy -a \
"src=/etc/hosts dest=/tmp/hosts"
# polling
ansible hosts -a "$prog" -f 10 -B 3600 -P 10
# check by asyc_status
ansible hosts -a "$prog" -f 10 -B 3600 &
ansible hosts -m sync_status -a "jid=123456789"
[myhosts]
10.30.1.[2:253]
nuclear.apua.idv.tw ansible_ssh_port=32768
blog.apua.idv.tw http_port=8000
production ansible_ssh_host=10.30.1.1
[test_servers]
10.30.1.[2:253]
[apua_domain]
nuclear.apua.idv.tw
blog.apua.idv.tw
[own:children]
test_servers
apua_domain
[myhosts]
blog.apua.idv.tw
nuclear[01:10].apua.idv.tw
[myhosts:vars]
ntp_server=time.stdtime.gov.tw
/etc/ansible/group_vars/own/ntp_settings
/etc/ansible/group_vars/test_servers/db_settings
/etc/ansible/host_vars/production
# ``./ec2.py`` would print out JSON format
ansible -i ec2.py -u ubuntu us-east-1d -m ping
# : := or
# :& := in
# :! := not in
webservers:dbservers:&staging:!phoenix
---
- hosts: 10.30.1.68
vars:
http_port: 80
max_clients: 200
tasks:
- name: debug var
debug: vars=http_port
PLAY [10.30.1.68] *************************************************************
GATHERING FACTS ***************************************************************
<10.30.1.68> REMOTE_MODULE setup
ok: [10.30.1.68]
TASK: [debug var] *************************************************************
ok: [10.30.1.68] => {
"msg": "Hello world!"
}
PLAY RECAP ********************************************************************
10.30.1.68 : ok=2 changed=0 unreachable=0 failed=0
tasks:
- command: echo {{ item }}
with_items: [ 0, 2, 4, 6, 8, 10 ]
when: item > 5
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
ansible-galaxy init apua_role -p ./roles
roles
└──apua_role/
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ └── main.yml
├── templates
└── vars
└── main.yml
---
- hosts: all
vars_prompt:
- name: "release_version"
prompt: "Product release version"
default: "1.0"
paramiko
Usage: ansible-pull [options] [playbook.yml]
- hosts: all
vars:
contents:
"{{ lookup('file', '/etc/foo.txt') }}"
ansible-vault create xxx.yml
ansible-vault edit xxx.yml
ansible-playbook xxx.yml --ask-vault-pass
ansible-playbook xxx.yml --vault-password-file ~/.print_pass.py
CFEngine: DSL Puppet: DSL, Ruby Chef: DSL Salt: YAML, Jinja2, DSL Ansible: YAML, Jinja2 (-), any lang (+)
CFEngine: 1993
Bcfg2: 2005
Puppet: 2005
Chef: 2009
Salt: 2011
Ansible: 2012