首页 文章

Ansible with_items并注册[重复]

提问于
浏览
1

这个问题在这里已有答案:

我是ansible的新手,并试图创建一个将延长已经具有特定过期日期的用户帐户列表的过期日期的剧本 . 任何具有不同日期或设置为永不的帐户都不应受到影响 .

虽然第一部分执行正常,但它似乎会覆盖每个用户的expiration_date _ {}的值 .

任何想法如何去做 .

---  
- hosts: all  
  become: true  
  tasks:  
  - name: Check accounts expiration dates  
    shell: "chage -l  {{ item }} | grep 'Account expires' | cut -d':' -f2"  
    args:  
      warn: no  
    register: expiration_date_{{item}}  
    with_items:  
      - user1  
      - user2  
      - user3  

  - name: Extend expiration date  
    user: name={{ item }} expires=1540944000  
    when: "'May 31' in expiration_date_{{item}}.stdout"  
    with_items:  
      - user1  
      - user2  
      - user3 
...

1 回答

  • -1

    我认为你基本上想要循环2个任务而不是一个 . 在这种情况下,您可以使用这两个任务创建一个单独的文件(使用YAML语法),并在主playbook中使用选项 include_tasks 并循环它 .

    Here is an example

相关问题