我的脚本正常工作,它看起来像这样:
- name: create a test user
shell: /usr/local/bin/wp/wp-cli.phar user create {{ item.name }} {{ item.email }} --user_pass={{ item.password }} --role={{ item.role }} --path=/var/www/wp
with_items:
- { name: 'testuser1', email: 'testuser1@123.com', password: 123, role: author }
- { name: 'testuser2', email: 'testuser2@123.com', password: 123, role: author }
这适用于创建wordpress用户,但我想知道是否有办法在with_items
中获取信息并将其移动到仅包含用户名和信息的单独文件中?
答案 0 :(得分:0)
在variable file (referenced with vars_files
)中:
users:
- name: testuser1
email: testuser1@123.com
password: 123
role: author
- name: testuser2
email: testuser2@123.com
password: 123
role: author
然后:
- name: create a test user
shell: /usr/local/bin/wp/wp-cli.phar user create {{ item.name }} {{ item.email }} --user_pass={{ item.password }} --role={{ item.role }} --path=/var/www/wp
with_items: "{{users}}"