2024年最全DO447管理任务执行--运行选定的任务_do447考题,白嫖党最爱

img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

image-20220410204904035

要只运行第一个任务,可以使用 --tags参数:

image-20220410204935173

因为指定了 --tags选项,所以playbook只运行带有webserver标签。

为 --tags指定多个标签,以逗号分隔的列表:

[user@demo ~]$ ansible-playbook main.yml --tags install,setup

使用 --skip-tags选项跳过带有特定标记的任务,只运行没有该标记的任务:

image-20220410204954551

要列出剧本中存在的所有标记,请将 --list-tags选项传递给ansible-playbook命令。例如:

image-20220410205015535


📜3.3 特殊标签

Ansible有一个特殊的方法,可以在剧本中分配:always.。标记了always的资源将始终运行,即使它与传递给 --tags的标签列表不匹配。唯一的例外是使用 --skip-tags always选项显式跳过它。

使用never特殊标记标记的任务不会运行,除非您将 --tags选项设置为never或与该任务关联的另一个tag运行playbook。

有三个额外的特殊tag:

  • tagged的标记将使用显式标记运行任何资源。
  • 未标记的tag将运行任何没有显式tag的资源,并排除所有标记的资源。
  • all tag将包含play中的所有任务,无论他们是否有tag。这是Ansible的默认行为。

📜详细参考官网

https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html

ansible-playbook offers five tag-related command-line options:

  • –tags all - run all tasks, ignore tags (default behavior)
  • –tags [tag1, tag2] - run only tasks with the tags tag1 and tag2
  • –skip-tags [tag3, tag4] - run all tasks except those with the tags tag3 and tag4
  • –tags tagged - run only tasks with at least one tag
  • –tags untagged - run only tasks with no tags

📜3.4 课本练习

[student@workstation ~]$ lab task-tagging start

📑拉取实验代码
[student@workstation ~]$ mkdir -p /home/student/git-repos/
[student@workstation ~]$ cd git-repos/
[student@workstation git-repos]$ git clone http://git.lab.example.com:8081/git/task-tagging.git
[student@workstation git-repos]$ cd task-tagging

📑编写测试剧本
[student@workstation task-tagging]$ vim test_webapp.yml
---
- name: Web application smoke test
  hosts: web_servers
  gather\_facts: no
  tasks:
    - name: Verify content of http://localhost
      uri:
        url: http://localhost
        return\_content: yes
      register: test_url
      failed\_when: "'Hello from' not in test\_url.content"
      tags:
        - tests
[student@workstation task-tagging]$ cat site.yml
- name: Deploy HAProxy
  import\_playbook: deploy_haproxy.yml

- name: Deploy Web Server
  import\_playbook: deploy_apache.yml

- name: Deploy Web App
  import\_playbook: deploy_webapp.yml

- name: Test deployed Web App
  import\_playbook: test_webapp.yml

测试运行
[student@workstation task-tagging]$ ansible-playbook site.yml --tags tests
TASK [Verify content of http://localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
fatal: [serverc.lab.example.com]: FAILED! => {"ansible\_facts": {"discovered\_interpreter\_python": "/usr/libexec/platform-python"}, "changed": false, "content": "", "elapsed": 0, "failed\_when\_result": true, "msg": "Status code was -1 and not [200]: Request failed: <urlopen error [Errno 111] Connection refused>", "redirected": false, "status": -1, "url": "http://localhost"}
fatal: [serverb.lab.example.com]: FAILED! => {"ansible\_facts": {"discovered\_interpreter\_python": "/usr/libexec/platform-python"}, "changed": false, "content": "", "elapsed": 0, "failed\_when\_result": true, "msg": "Status code was -1 and not [200]: Request failed: <urlopen error [Errno 111] Connection refused>", "redirected": false, "status": -1, "url": "http://localhost"}

[student@workstation task-tagging]$ ansible-playbook site.yml --skip-tags tests
[student@workstation task-tagging]$ ansible-playbook site.yml --tags tests

📑清除实验

[student@workstation task-tagging]$ lab task-tagging finish


💡总结

RHCA认证需要经历5门的学习与考试,还是需要花不少时间去学习与备考的,好好加油,可以噶🤪。

以上就是【金鱼哥】对 第三章 管理任务执行–运行选定的任务 的简述和讲解。希望能对看到此文章的小伙伴有所帮助。

img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!**

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值