ansible剧本_您应该尝试的4种Ansible剧本

ansible剧本

在复杂的IT环境中,即使是最小的任务也似乎永远存在。 难以扩展,难以开发,部署和维护的系统。 业务需求只会增加复杂性,而IT团队会在管理,可用性和成本方面苦苦挣扎。

Ansible可以改善您当前的流程,迁移应用程序以进行更好的优化,并为整个组织内的DevOps实践提供一种语言。

更重要的是,您可以通过Ansible手册来声明配置,但是它们可以编排任何手动订购过程的步骤,即使不同的步骤必须在特定顺序的机器之间来回跳动。 他们可以同步或异步启动任务。

虽然您可以运行/usr/bin/ansible program执行临时任务,但更可能将剧本保留在源代码管理中,并用于推送您的配置或确保远程系统的配置符合规范。 因为Ansible剧本是配置,部署和编排语言,所以它们可以描述您希望远程系统执行的策略或一般IT流程中的一组步骤。

这里有四本Ansible剧本,您应该尝试进一步定制和配置自动化的工作方式。

管理Kubernetes对象

Kubernetes对象上执行CRUD操作时,Ansible剧本可让您通过OpenShift Python客户端快速轻松地访问所有Kubernetes API。 以下剧本片段向您展示了如何创建特定的Kubernetes命名空间和服务对象:


   
   
- name: Create a k8s namespace
  k8s:
    name: mynamespace
    api_version: v1
    kind: Namespace
    state: present

- name: Create a Service object from an inline definition
  k8s:
    state: present
    definition:
      apiVersion: v1
      kind: Service
      metadata:
        name: web
        namespace: mynamespace
        labels:
          app: galaxy
          service: web
      spec:
        selector:
          app: galaxy
          service: web
        ports:
        - protocol: TCP
          targetPort: 8000
          name: port-8000-tcp
          port: 8000

- name: Create a Service object by reading the definition from a file
  k8s:
    state: present
    src: /mynamespace/service.yml

# Passing the object definition from a file
- name: Create a Deployment by reading the definition from a local file
  k8s:
    state: present
    src: /mynamespace/deployment.yml

缓解诸如Meltdown和Spectre之类的关键安全问题

在1月的第一周,宣布了两个缺陷: Meltdown和Spectre 。 两者都涉及或多或少的地球上每个计算设备(处理器)的核心硬件。 这里对这两个缺陷进行了深入的深入研究 。 虽然Meltdown和Spectre并未完全缓解,但以下剧本摘要显示了如何轻松地为Windows部署补丁:


   
   
- name: Patch Windows systems against Meltdown and Spectre
  hosts: "{{ target_hosts | default('all') }}"

  vars:
    reboot_after_update: no
    registry_keys:
      - path: HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management
        name: FeatureSettingsOverride
        data: 0
        type: dword

      - path: HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management
        name: FeatureSettingsOverrideMask
        data: 3
        type: dword

      # https://support.microsoft.com/en-us/help/4072699
      - path: HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\QualityCompat
        name: cadca5fe-87d3-4b96-b7fb-a231484277cc
        type: dword
        data: '0x00000000'

  tasks:
    - name: Install security updates
      win_updates:
        category_names:
          - SecurityUpdates
      notify: reboot windows system

    - name: Enable kernel protections
      win_regedit:
        path: "{{ item.path }}"
        name: "{{ item.name }}"
        data: "{{ item.data }}"
        type: "{{ item.type }}"
      with_items: "{{ registry_keys }}"

  handlers:
    - name: reboot windows system
      win_reboot:
        shutdown_timeout: 3600
        reboot_timeout: 3600
      when: reboot_after_update

您还可以找到其他适用于Linux的剧本

将CI / CD流程与Jenkins集成

Jenkins是用于实施CI / CD的著名工具。 Shell脚本通常用于供应环境或在管道流程期间部署应用程序。 尽管这可行,但是从长远来看,维护和重用脚本很麻烦。 以下剧本摘要显示了如何使用Jenkins Pipeline在持续集成/持续交付(CI / CD)流程中配置基础结构。


   
   
---
- name: Deploy Jenkins CI
hosts: jenkins_server
remote_user: vagrant
become: yes

roles:
  - geerlingguy.repo-epel
  - geerlingguy.jenkins
  - geerlingguy.git
  - tecris.maven
  - geerlingguy.ansible

- name: Deploy Nexus Server
hosts: nexus_server
remote_user: vagrant
become: yes

roles:
  - geerlingguy.java
  - savoirfairelinux.nexus3-oss

- name: Deploy Sonar Server
hosts: sonar_server
remote_user: vagrant
become: yes

roles:
  - wtanaka.unzip
  - zanini.sonar

- name: On Premises CentOS
hosts: app_server
remote_user: vagrant
become: yes

roles:
  - jenkins-keys-config

使用Istio启动服务网格

在云平台上,开发人员必须使用微服务来构建可移植性。 同时,运营商正在管理超大型混合和多云部署。 通过Istio的服务网格,您可以通过专用基础架构(例如Envoy sidecar容器)连接,保护,控制和观察服务,而无需开发人员。 以下剧本片段显示了如何在计算机上本地安装Istio:


   
   
---

# Whether the cluster is an Openshift (ocp) or upstream Kubernetes (k8s) cluster
cluster_flavour: ocp

istio:
  # Install istio with or without istio-auth module
  auth: false

  # A set of add-ons to install, for example kiali
  addon: []

  # The names of the samples that should be installed as well.
  # The available samples are in the istio_simple_samples variable
  # In addition to the values in istio_simple_samples, 'bookinfo' can also be specified
  samples: []

  # Whether or not to open apps in the browser
  open_apps: false

  # Whether to delete resources that might exist from previous Istio installations
  delete_resources: false

结论

您可以在ansible-examples资料库中找到全套说明这些技术的全套手册。 我建议您在进行操作时在另一个选项卡中查看这些内容。

希望这些Ansible手册的提示和摘要提供了一些有趣的方式来使用和扩展您的自动化之旅。

翻译自: https://opensource.com/article/18/8/ansible-playbooks-you-should-try

ansible剧本

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值