Presentation is loading. Please wait.

Presentation is loading. Please wait.

Edu.51cto.com 自动化运维 --Ansible. edu.51cto.com 讲师: Breeze Yan 自动化运维 QQ 群: 22346584.

Similar presentations


Presentation on theme: "Edu.51cto.com 自动化运维 --Ansible. edu.51cto.com 讲师: Breeze Yan 自动化运维 QQ 群: 22346584."— Presentation transcript:

1 edu.51cto.com 自动化运维 --Ansible

2 edu.51cto.com 讲师: Breeze Yan 自动化运维 QQ 群: 22346584

3 edu.51cto.com 课程目录 Course Contents 一、 Ansible 简介与 Hosts Inventory 二、 Ansible 常用模块 三、 Ansible Playbook 简单介绍 四、 Playbook 的角色及包含 五、 Playbook 常用模块 六、 Playbook 的变量 七、 Playbook 的条件判断 八、 Playbook 的循环 九、自定义模块 十、 Ansible 生产案例

4 edu.51cto.com Ansible Variables

5 edu.51cto.com Variables Defined in Inventory Variables Defined in a Playbook Variables Defined in Commandline Registered Variables Variables defined from included files and roles Using Variables: About Jinja2 Facts

6 edu.51cto.com Variables Defined in Inventory [webservers] app1_server http_port=80 [webservers:vars] some_server=foo.southeast.example.com halon_system_timeout=30 self_destruct_countdown=60 escape_pods=2 /etc/ansible/host_vars/app1_server /etc/ansible/group_vars/webservers

7 edu.51cto.com Variables Defined in a Playbook vars vars_files vars_prompt

8 edu.51cto.com Variables Defined in a Commandline - hosts: mfs_node user: "{{ uservar }}" tasks: - shell: echo "{{ echovar }}" ansible-playbook command_vars.yml -e 'uservar="root" echovar="hello world"' ansible-playbook command_vars.yml -e '{"uservar":"root", "echovar":"hello world"}' ansible-playbook command_vars.yml -e '@test.json' cat test.json uservar: root echovar: hello world

9 edu.51cto.com Registered Variables - hosts: mfs_node tasks: - shell: echo "5" register: result ignore_errors: True - debug: msg="it failed" when: result|failed - debug: msg="{{result.stdout}}" - shell: /usr/bin/bar when: result.rc == 5

10 edu.51cto.com roles

11 edu.51cto.com Using Variables: About Jinja2 template: src=foo.cfg.j2 dest={{ remote_install_path }}/foo.cfg {{ some_variable | default(5) }}

12 edu.51cto.com Facts system facts local facts

13 edu.51cto.com System Facts ansible -m setup

14 edu.51cto.com Local Facts - hosts: webservers tasks: - name: create directory for ansible custom facts file: state=directory recurse=yes path=/etc/ansible/facts.d - name: install custom impi fact copy: src=ipmi.fact dest=/etc/ansible/facts.d - name: re-read facts after adding custom fact setup: filter=ansible_local cat ipmi.fact [general] asdf=1 bar=2

15 edu.51cto.com Registered Variables - hosts: web_servers tasks: - shell: /usr/bin/foo register: foo_result ignore_errors: True - shell: /usr/bin/bar when: foo_result.rc == 5

16 edu.51cto.com Omitting Undefined Variables - name: touch files with an optional mode file: dest={{item.path}} state=touch mode={{item.mode|default(omit)}} with_items: - path: /tmp/foo - path: /tmp/bar - path: /tmp/baz mode: "0444"

17 edu.51cto.com A YAML Gotcha #This won’t work: - hosts: app_servers vars: app_path: {{ base_path }}/22 #Do it like this and you’ll be fine: - hosts: app_servers vars: app_path: "{{ base_path }}/22"

18 edu.51cto.com Thank You ! edu.51cto.com


Download ppt "Edu.51cto.com 自动化运维 --Ansible. edu.51cto.com 讲师: Breeze Yan 自动化运维 QQ 群: 22346584."

Similar presentations


Ads by Google