ansible第四天
创始人
2024-05-09 00:54:54
0

1.按照要求定义以下变量。(可以在多个位置下定义实现相应操作即可)

| 变量名 | 值 |
| --------- | ------- |
| file_name | newfile |
| user_name | devops |
| pk_name | httpd |

2.编写任务模块在node1和node2主机中根据以上变量值创建对应文本文件以及用户名和安装软件包。

1.按照要求定义以下变量。(可以在多个位置下定义实现相应操作即可)

变量名           值
file_name      newfile
user_name    devops
pk_name       httpd
2.编写任务模块在node1和node2主机中根据以上变量值创建对应文本文件以及用户名和安装软件包。

[root@server playbook]# vim var.yml 

---

- name: day04
  hosts: node1,node2
  vars:
    - file_name: newfile
    - user_name: devops
    - pk_name: httpd
  tasks:
    - name: 创建文件
      file:
        path: /{{ file_name }}
        state: touch
    - name: 创建用户
      user:
        name: "{{ user_name }}"
        state: present
        system: yes
    - name: 安装HTTPD
      yum:
        name: "{{ pk_name }}"
        state: present


[root@server playbook]# ansible-playbook var.yml 

PLAY [day04] ***********************************************************************************

TASK [Gathering Facts] *************************************************************************
ok: [node1]
ok: [node2]

TASK [创建文件] ********************************************************************************
changed: [node1]
changed: [node2]

TASK [创建用户] ********************************************************************************
changed: [node1]
changed: [node2]

TASK [安装HTTPD] *******************************************************************************
ok: [node1]
ok: [node2]

PLAY RECAP *************************************************************************************
node1                      : ok=4    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
node2                      : ok=4    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 


[root@node1 /]# ll
total 30
lrwxrwxrwx.   1 root root    7 Jun 21  2021 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Oct 14 19:38 boot
drwxr-xr-x.  19 root root 3180 Jan  4 09:34 dev
drwxr-xr-x. 154 root root 8192 Jan  6 09:57 etc
drwxr-xr-x.   6 root root   56 Jan  6 09:57 home
lrwxrwxrwx.   1 root root    7 Jun 21  2021 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Jun 21  2021 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Jun 21  2021 media
dr-xr-xr-x.   7 root root 2048 Oct 13  2021 mnt
-rw-r--r--.   1 root root    0 Jan  6 09:56 newfile  
 

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
ChatGPT 怎么用最新详细... ChatGPT 以其强大的信息整合和对话能力惊艳了全球,在自然语言处理上面表现出了惊人...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...