Using Ansible ver. core 2.13.3. This is the main task
- name: Add WP admin users
command: wp user create "{{ item.login }}" "{{ item.email }}"
--role="{{ item.role }}"
--user_pass="{{ item.pwd }}"
--first_name="{{ item.first }}"
--last_name="{{ item.last }}"
--user_nicename="{{ item.nice }}"
--nickname="{{ item.nick }}"
--display_name="{{ item.display }}"
args:
chdir: "/var/www/{{ domain_name }}"
become: yes
become_user: www-data
with_items:
- { login: user1, email: email1@domain.tld, role: administrator, pwd:XXX, first: John, last: Doe, nice: John, nick: John, display: John }
- { login: user2, email: email2@domain.tld, role: administrator, pwd: YYY, first: Mark, last: Twain, nice: Mark, nick: Mark, display: Mark }
This is the group_vars/all.yml
domain_name: "domain.tld/dev"
and this is the inventory file
[servers]
dev.domain.tld ansible_ssh_host=178.xxx.xxx.xxx
and finally this is my playbook:
- name: Setup
hosts: servers
gather_facts: false
become: true
roles:
- wpadmin
Everything is working fine. Now I would like to run this same playbook against other websites (Ex. domain.tld/qa, and domain.tld/staging) all sites at once. I tried to add a list of variables like this:
domain_name:
- "domain.tld/dev"
- "domain.tld/qa"
then changing the args line like this: chdir: "/var/www/{{ item.domain_name }}"
but an error shows up:
The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'domain_name'