bingooyong / note

1 stars 1 forks source link

玩转 Ansible #22

Open bingooyong opened 4 years ago

bingooyong commented 4 years ago

占楼

bingooyong commented 4 years ago

查找rpm是否安装


[vagrant@bogon ~]$ yum --disablerepo='*' list installed  libselinux-python
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
已安装的软件包
libselinux-python.x86_64 2.2.2-6.el7  @anaconda
[vagrant@bogon ~]$ `which yum` list installed libselinux-python | grep libselinux-python | awk '{print $2}' | cut -d'-' -f1
2.2.2
[vagrant@bogon ~]$ rpm -q libselinux-python
libselinux-python-2.2.2-6.el7.x86_64

```bash
bingooyong commented 2 years ago
---
  - hosts: dev
    tasks:
     - name: create user
       user:
         name: "{{ item.user }}"    #循环 添加user1~3a
         password: "{{ 'item.pass' | password_hash('sha512') }}"    #采用哈希加密
         state: present
       loop:
         - { user: 'use1', pass: 'password1'}
  - hosts: dev
    # 互信用户
    user: use1
    tasks:
      - name: ssh-copy
        authorized_key: user=use1 key="{{ lookup('file', '/home/use1/.ssh/id_ed25519.pub') }}"