ansible-playbook

Ansible: Store command's stdout in new variable?

核能气质少年 提交于 2019-11-29 19:56:28
Inside my playbook I'd like to create a variable holding the output of an external command. Afterwards I want to make use of that variable in a couple of templates. Here are the relevant parts of the playbook: tasks: - name: Create variable from command command: "echo Hello" register: command_output - debug: msg="{{command_output.stdout}}" - name: Copy test service template: src=../templates/test.service.j2 dest=/tmp/test.service - name: Enable test service shell: systemctl enable /tmp/test.service - name: Start test service shell: systemctl start test.service and let's say this is my template

how to define ssh private key for servers fetched by dynamic inventory in files

淺唱寂寞╮ 提交于 2019-11-29 19:42:55
I met one configuration problem when coding ansible playbook for ssh private key file. As we know, we can define combination with host server, ip & related ssh private key in ansible hosts file for static inventory servers. But i have no idea how to define that with dynamic inventory servers. Ex: --- - hosts: tag_Name_server1 gather_facts: no roles: - role1 - hosts: tag_Name_server2 gather_facts: no roles: - roles2 Below command is used to call that playbook: ansible-playbook test.yml -i ec2.py --private-key ~/.ssh/SSHKEY.pem My question is: How can i define ~/.ssh/SSHKEY.pem in ansible files

Ansible loop over variables

大憨熊 提交于 2019-11-29 19:14:20
问题 i am using ansible to update configuration file of newly added NIC for that i have defined some variables in separate yml file /tmp/ip.yml #first interface interface1: eth1 bootproto1: static ipaddress1: 192.168.211.249 netmask1: 255.255.255.0 gateway: 192.168.211.2 DNS1: 192.168.211.2 #second interface interface2: eth2 bootproto2: static ipaddress2: 10.0.0.100 netmask2: 255.0.0.0 Playbook - include_vars: /tmp/ip.yml - name: configuring interface lineinfile: state=present create=yes dest=/etc

ansible - variable within variable

China☆狼群 提交于 2019-11-29 17:23:17
问题 Ansible 1.9.2 version. Does Ansible supports variable expansion within a variable while evaluating it. I have a task to download 3 zip files from Artifactory. Instead of writing 3 separate tasks within the role, I used ansible's loop in the playbook. In Ansible role's default/main.yml, I have all the required variables defined/available to the role i.e. jmeterplugins_extras_artifactory_url and other (standard / webdriver) are visible to perf_tests role. --- #- Download and install

Ansible wait_for module, start at end of file

久未见 提交于 2019-11-29 12:24:55
With the wait_for module in Ansible if I use search_regex='foo' on a file it seems to start at the beginning of the file, which means it will match on old data, thus when restarting a process/app (Java) which appends to a file rather than start a new file, the wait_for module will exit true for old data, but I would like to check from the tail of the file. Regular expression in search_regex of wait_for module is by default set to multiline. You can register the contents of the last line and then search for the string appearing after that line (this assumes there are no duplicate lines in the

How to use 'skip: true' with 'with_first_found'?

自作多情 提交于 2019-11-29 12:13:58
I would like to use the following task in a playbook: - include: "{{ prerequisites_file }}" with_first_found: - "prerequisites-{{ ansible_distribution }}.yml" - "prerequisites-{{ ansible_os_family }}.yml" loop_control: loop_var: prerequisites_file I would like it to just pass if no files matching the architecture were found. When run as is, in such a case, it produces an error: TASK [ansible-playbook : include] *************************************** fatal: [ansible-playbook]: FAILED! => {"failed": true, "msg": "No file was found when using with_first_found. Use the 'skip: true' option to

Ansible: overriding dictionary variables in extra-vars [duplicate]

故事扮演 提交于 2019-11-29 11:35:11
This question already has an answer here: Ansible. override single dictionary key [duplicate] 4 answers In my Ansible playbook I have a nested variable declaration as shown below in a variable file. repo: branch: int url: git@github:user/repo.git dest: "/var/code" How would I override the branch param in extra-vars? I tried something like this below but it didn't work. --extra-vars "repo.branch=exec_refactor" neither this --extra-vars "repo[branch]=exec_refactor" using JSON representation like below results in overriding the entire repo node and hence repo.branch is successfully overridden but

Ansible: Access host/group vars from within custom module

情到浓时终转凉″ 提交于 2019-11-29 09:55:23
Is there a way how one can access host/group vars from within a custom written module ? I would like to avoid to pass all required vars as module parameters. My module is written in Python and I use the boilerplate. I checked pretty much all available vars but they are not stored anywhere: def main(): pprint(dir()) pprint(globals()) pprint(locals()) for name in vars().keys(): print(name) Now my only hope is they are somehow accessible through the undocumented module utils. I guess it is not possible, since the module runs on the target machine and probably the facts/host/group vars are not

remove all files containing a certain name within a directory

百般思念 提交于 2019-11-29 09:18:56
I have the following directory and it has the following /tmp/test/file1.txt /tmp/test/file1.txt.backup /tmp/test/mywords.csv How do I use the file component to just remove file1* files?? edit: Ansible 2.0 has been released now, so the previous answer should work, and you can also now loop over fileglobs . Note this only works if you are running Ansible locally: - file: path: "{{item}}" state: absent with_fileglob: - /tmp/test/file* original answer: I can't find a way to do this currently without dropping to the shell, however if you can drop to the shell to gather a list of files that match

How to get the installed yum packages with Ansible?

岁酱吖の 提交于 2019-11-29 08:24:42
I am trying to get all the installed yum package on an RHEL machine. I can easily get it through using shell commands which is not idempotent and would like to use the yum command instead. Shell command works fine: - name: yum list packages shell: yum list installed > build_server_info.config But when I try to use the yum command it just executes but do not give any results: - name: yum_command action: yum list=${pkg} list=available I can easily get it through using shell commands which is not idempotent You can't really talk about idempotence, when you are querying the current state of a