ansible-playbook

ansible ignore the run_once configuration on task

随声附和 提交于 2019-12-09 08:31:45
问题 I am using Ansible and I want to run a task only once. I follow the documentation about how to configure and run a task only once - name: apt update shell: apt-get update run_once: true But when I run Ansible, it always runs this task. How can I run my task only once. 回答1: The run_once option will run every time your Playbook/tasks runs, but will only run it once during the specific run itself. So every time you run the play, it will run, but only on the first host in the list. If you're

Ansible - Define Inventory at run time

故事扮演 提交于 2019-12-09 07:03:33
问题 I am liitle new to ansible so bear with me if my questions are a bit basic. Scenario: I have a few group of Remote hosts such as [EPCs] [Clients] and [Testers] I am able to configure them just the way I want them to be. Problem: I need to write a playbook, which when runs, asks the user for the inventory at run time. As an example when a playbook is run the user should be prompted in the following way: "Enter the number of EPCs you want to configure" "Enter the number of clients you want to

Ansible: Abort Execution if a host is unreachable

送分小仙女□ 提交于 2019-12-08 20:47:36
问题 Summary: A better way for aborting ansible playbook immediately if any host is unreachable. Is there a way to abort Ansible playbook if any one of the host is unreachable. What I find that if it cannot reach a host it will still continue on and execute all the plays/tasks in the playbook. All my playbooks I specify the max_fail_percentage of 0, but in this case ansible does not complain since all the hosts that are reachable can execute all the plays. Currently I have a simple but hacky

ssl: auth method ssl requires a password

≡放荡痞女 提交于 2019-12-08 16:44:05
问题 While trying to connect to a windows VM through Ansible I get this issue: TASK [setup] ******************************************************************* <10.xx.xx.xx> ESTABLISH WINRM CONNECTION FOR USER: winad-admin on PORT 5986 TO 10.xx.xx.xx fatal: [10.xx.xx.xx]: UNREACHABLE! => {"changed": false, "msg": "ssl: auth method ssl requires a password", "unreachable": true} Inventory file : ---hosts--- [win_servers] 10.xx.xx.xx [nonprod1_ad_servers:vars] ansible_user=administrator ansible_pass

Ansible Module “lineinfile” replace multiple lines in several files

杀马特。学长 韩版系。学妹 提交于 2019-12-08 10:50:54
问题 our SSL certificate runs out in a couple of days. So I thought Ansible can put the new certs on the server und change the apache2 sites. Serveral sites are running on this server. I want to replace the following lines: SSLCertificateChainFile SSLCertificateKeyFile SSLCertificateFile I use this command to get a list of all sites in /etc/apache2 where the pattern "SSLCertificate" exists. - name: Apache 2.2 list sites files and store it in register command: grep -lR --exclude default-ssl

Adding hosts to Ansible host file

谁说胖子不能爱 提交于 2019-12-08 08:17:01
问题 I have been trying to add a host name to my hosts file using an Ansible playbook. My Ansible play look as below and my host file resides at /etc/ansible/hosts : - name: adding host playbook hosts: localhost connection: local tasks: - name: add host to ansible host file add_host: name: myvm.cloud.azure.com groups: mymasters Playbook executes successfully, but the new host name is not added to the Ansible hosts file. Can anybody help me on this? 回答1: add_host module does not add a host to your

Ansible writing output from multiple task to a single file

若如初见. 提交于 2019-12-08 07:37:41
问题 In Ansible, I have written an Yaml playbook that takes list of host name and the executes command for each host. I have registered a variable for these task and at the end of executing a task I append output of each command to a single file. But every time I try to append to my output file, only the last record is getting persisted. --- - hosts: list_of_hosts become_user: some user vars: output: [] tasks: - name: some name command: some command register: output failed_when: "'FAILED' in

How to copy file to local directory using Ansible?

折月煮酒 提交于 2019-12-08 06:24:06
问题 I'm trying to set up a playbook that will configure my development system. I'd like to copy the /etc/hosts file from my playbooks "files" directory to the /etc directory on my system. Currently I'm doing the following: # main.yml - hosts: all - tasks: - copy: src=files/hosts dest=/etc/hosts owner=root group=wheel mode=0644 backup=true become: true # inventory localhost ansible_connection=local When I run the playbook I'm getting this error: fatal: [localhost]: FAILED! => {... "msg": Failed to

How to break `with_lines` cycle in Ansible?

心已入冬 提交于 2019-12-08 03:30:31
问题 I would like to use the following handler with Ansible: - name: force ntp update shell: ntpdate {{item}} with_lines: /etc/ntpd.serverlist But I want it to end execution after the first successful execution (the list contains ntpd servers with which you can attempt to sync. One is enough). How would I do that? 回答1: That's a very interesting situation you have. I haven't tried this personally, but I wonder if something like this would work: - name: force ntp update shell: ntpdate {{item}} with

Ansible - Control commands when need users input when executing

China☆狼群 提交于 2019-12-08 02:04:19
问题 How can i control user inputs when a command is executing and ask me something for example : sudo apt-get install mariadb-server when you run this command in ubuntu it asked you please enter new password for mysql user root and then again it ask to enter password again for confirmation . how can i pass a variable for example mariadbpass to this command because everytime ansible run this hangs and failed so i have to login to servers and run manually this dpkg --configure -a to enter prompted