ansible-playbook -i server_hosts app_install_main.yml
├── server_hosts├── app_install│ ├── README.md│ ├── defaults│ │ └── main.yml│ ├── files│ ├── handlers│ │ └── main.yml│ ├── meta│ │ └── main.yml│ ├── tasks│ │ └── app_install_task.yml│ ├── templates│ ├── tests│ │ ├── inventory│ │ └── test.yml│ └── vars│ └── main.yml├── app_install_main.yml
---# tasks file for app_install
- name: Install required nfs packages yum: name={{ item }} state=present with_items: - nfs-utils - nfs-utils-lib
- name: Create a temporary mount point for the installation files file: path=/tmp/app_install state=directory owner=root group=root mode=0775
- name: Mount the nfs share from nfsshare.domain.tld shell: mount -F -t nfs -o vers=3 -v nfsshare.domain.tld:/share/location /tmp/app_install
- name: Install app on test systems command: /tmp/app_install/apptool_install arg1 when: ({{ test }})
- name: Join test systems to test ou shell: /path/to/domainjoin-cli join --notimesync --disable hostname --ou OU=test,OU=UNIX,DC=server,DC=domain,DC=tld server.domain.tld join_account when: ({{ test }})
---
- name: install app and join systems to domain hosts: "{{ test }}" become: yes
roles: - app_install
vars_prompt: - name: "ansible_sudo_pass" prompt: "Sudo password" private: yes
[testsystems]
testserver1.domain.tld
[developmentsystems]
devserver1.domain.tld
devserver2.domain.tld
[productionsystems]
prodserver1.domain.tld
prodserver2.domain.tld
[testservers:children]testsystems
[dev-servers:children]developmentsystems
[prod-servers:children]productionsystems
---# vars file for app_install
test: "{{ testservers }}"
~/git/ansible/roles$ tree.└── project1
├── server_hosts ├── app_install │ ├── README.md │ ├── defaults │ │ └── main.yml │ ├── files │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── main.yml │ ├── tasks │ │ └── app_install_task.yml │ ├── templates │ ├── tests │ │ ├── inventory │ │ └── test.yml │ └── vars │ └── main.yml ├── app_install_main.yml
---# vars file for app_install
test: "{{ testservers }}"
---# vars file for app_install
test: "testservers"
Sudo password:
PLAY [install app and join appropriate ou] ******************
TASK [setup] *******************************************************************ok: [testserver1.domain.tld]
PLAY RECAP *********************************************************************testserver1.domain.tld : ok=1 changed=0 unreachable=0 failed=0
~/git/ansible$ tree.└── project1 ├── server_hosts ├── roles │
└
── app_install
│
├── README.md │
├── defaults │
│ └── main.yml │
├── files │
├── handlers │
│ └── main.yml │
├── meta │
│ └── main.yml │
├── tasks
│
│ └── main.yml
[WARNING]: provided hosts list is empty, only localhost is available
Sudo password:
PLAY [install app and join appropriate ou] ******************
skipping: no hosts matched
PLAY RECAP *********************************************************************
---
test: testservers
ERROR! ERROR! 'testservers' is undefined
- name: install app and
join systems to domain
hosts: testservers
become: yes
[testsystems]
testserver1.domain.tld
[developmentsystems]
devserver1.domain.tld
devserver2.domain.tld
[productionsystems]
prodserver1.domain.tld
prodserver2.domain.tld
[testservers:children]testsystems
[dev-servers:children]developmentsystems
[prod-servers:children]productionsystems
---
test: testservers
- name: install app and join systems to domain
hosts: testservers
become: yes
---# tasks file for app_install
- name: Install required nfs packages yum: name={{ item }} state=present with_items: - nfs-utils - nfs-utils-lib
- name: Create a temporary mount point for the installation files file: path=/tmp/app_install state=directory owner=root group=root mode=0775
- name: Mount the nfs share from nfsshare.domain.tld shell: mount -F -t nfs -o vers=3 -v nfsshare.domain.tld:/share/location /tmp/app_install
- name: Install app on test systems command: /tmp/app_install/apptool_install arg1
when: ({{ testserver }})
- name: Join test systems to test ou shell: /path/to/domainjoin-cli join --notimesync --disable hostname --ou OU=test,OU=UNIX,DC=server,DC=domain,DC=tld server.domain.tld join_account
when: ({{ testserver }})
Sudo password:
PLAY [install app and join systems to appropriate ou] ******************
TASK [setup] *******************************************************************ok: [testserver1.domain.tld]
TASK [app_install : Install required nfs packages] *********************changed: [testserver1.domain.tld] => (item=[u'nfs-utils', u'nfs-utils-lib'])
TASK [app_install : Create a temporary mount point for the installation files] ***changed: [testserver1.domain.tld]
TASK [app_install : Mount the nfs share] *********************skipping: [testserver1.domain.tld]
TASK [app_install : Install app on test systems] ***************fatal: [testserver1.domain.tld]: FAILED! => {"failed": true, "msg": "ERROR! The conditional check '{{ testserver }}' failed. The error was: ERROR! error while evaluating conditional ({{ testserver }}): ERROR! 'testserver' is undefined\n\nThe error appears to have been in '/git/ansible/projects/app/roles/app_install/tasks/main.yml': line 16, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Install app on testserver systems\n ^ here\n"}
PLAY RECAP *********************************************************************testserver1.domain.tld : ok=3 changed=2 unreachable=0 failed=1
Overall, you are better off customizing your plays for each group (maybe in separate playbooks) instead of trying to make a one-size-fits-all playbook. Tasks can be reused by either importing them or putting them in roles.
The other nice thing about this model is that when you run ansible-playbook --list-roles, you get a nice documented output (assuming you named all of your tasks) of what will happen.
However, since we're already here....
Also, what do you mean by "moved it up one level"?
---
- name: install app and join systems to domain hosts: testservers
become: yes
roles: - app_install
vars_prompt: - name: "ansible_sudo_pass" prompt: "Sudo password" private: yes
---# tasks file for app_install
- name: Install required nfs packages yum: name={{ item }} state=present with_items: - nfs-utils - nfs-utils-lib
- name: Create a temporary mount point for the installation files file: path=/tmp/app_install state=directory owner=root group=root mode=0775
- name: Mount the nfs share from nfsshare.domain.tld shell: mount -F -t nfs -o vers=3 -v nfsshare.domain.tld:/share/location /tmp/app_install
- name: Install app on test systems command: /tmp/app_install/apptool_install arg1
when: "'testserver'in group_names"
- name: Join test systems to test ou shell: /path/to/domainjoin-cli join --notimesync --disable hostname --ou OU=test,OU=UNIX,DC=server,DC=domain,DC=tld server.domain.tld join_account
when: "'testserver' in group_names"
That "when" should be checking for "testservers" (plural).
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/GsGIlwrqU_0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/88286b9c-a89f-4454-a9ef-c10d7d5d4367%40googlegroups.com.
---
- name: Run on prod
include: prod.yml
when: run_prod|default(false)
- name: Run on dev
include: prod.yml
when: run_dev|default(false)
- name: Run on test
include: test.yml
when: run_test|default(false)
---
- name: Play for test servers
hosts: testservers
roles:
- { role: app_install, run_test: true, tags: test }
- name: Play for dev servers
hosts: dev-servers
roles:
- { role: app_install, run_dev: true, tags: dev }
- name: Play for prod servers
hosts: prod-servers
roles:
- { role: app_install, run_prod: true, tags: prod }
when: "'testservers'in group_names"
- name: Join test systems to test ou shell: /path/to/domainjoin-cli join --notimesync --disable hostname --ou OU=test,OU=UNIX,DC=server,DC=domain,DC=tld server.domain.tld join_account
when: "'testservers' in group_names"
roles└── powerbroker ├── powerbroker_install │ ├── pb_install_dev │ │ ├── README.md
│ │ ├── defaults │ │ │ └── main.yml │ │ ├── files │ │ ├── handlers │ │ │ └── main.yml │ │ ├── meta │ │ │ └── main.yml │ │ ├── tasks
│ │ │ └── main.yml │ │ ├── templates
│ │ ├── tests │ │ │ ├── inventory │ │ │ └── test.yml │ │ └── vars │ │ └── main.yml
│ ├── pb_install_prod │ │ ├── README.md
│ │ ├── defaults │ │ │ └── main.yml │ │ ├── files │ │ ├── handlers │ │ │ └── main.yml │ │ ├── meta │ │ │ └── main.yml │ │ ├── tasks
│ │ │ └── main.yml │ │ ├── templates
│ │ ├── tests │ │ │ ├── inventory │ │ │ └── test.yml │ │ └── vars │ │ └── main.yml
│ ├── pb_install_test │ │ ├── README.md
│ │ ├── defaults │ │ │ └── main.yml │ │ ├── files │ │ ├── handlers │ │ │ └── main.yml │ │ ├── meta │ │ │ └── main.yml │ │ ├── tasks
│ │ │ └── main.yml │ │ ├── templates
│ │ ├── tests │ │ │ ├── inventory │ │ │ └── test.yml │ │ └── vars │ │ └── main.yml
│ ├── powerbroker_hosts │ └── site.yml
---# tasks file for pb_install_test
- name: install required nfs packages
yum: name={{ item }} state=present with_items: - nfs-utils - nfs-utils-lib
- name: mount nfs share mount: name=/tmp/pb_install src="hostname.server.com:/src/path" fstype=nfs opts="vers=3" state=mounted
- name: install pbis and pbul shell: /tmp/pb_install/pbis_install e1
- name: join systems to domain and correct ou shell: /opt/pbis/bin/domainjoin-cli join --notimesync --disable hostname --ou OU=UNIX,OU=Servers,DC=sub,DC=domain,DC=com subdomain.server.com
---
########################## Test Servers ###########################
- name: install powerbroker (pbis and pbul) to all test servers
hosts: e1servers
become: yes
roles:
- pb_install_test
########################## Dev Servers ###########################
#- name: install powerbroker (pbis and pbul) to all dev servers
# hosts: e2servers
# become: yes
# roles:
# - pb_install_dev
########################## Prod Servers ###########################
#- name: install powerbroker (pbis and pbul) to all prod servers
# hosts: e3servers
# become: yes
# roles:
# - pb_install_prod
########################## Variables Prompt ########################
vars_prompt:
- name: "ansible_sudo_pass"
prompt: "SUDO password"
private: yes
- name: join systems to domain and correct ou
shell: /opt/pbis/bin/domainjoin-cli join --notimesync --disable hostname --ou OU=UNIX,OU=Servers,DC=sub,DC=domain,DC=com subdomain.server.com
- name: join systems to domain and correct ou expect: command: /bin/bash -c "/opt/pbis/bin/domainjoin-cli join --notimesync --disable hostname --ou OU=UNIX,OU=Servers,DC=sub,DC=domain,DC=com subdomain.server.com" responses: Password for Administrator: "password123"